S
S
starter22017-07-05 07:19:08
Java
starter2, 2017-07-05 07:19:08

How can I accept a POST request from an Android app?

A post request has been written for the client, how to make the server part?
What php or mysql files are needed and how to prescribe in general so that there is a text output in black and white at the request link on the hosting?
Thank you in advance for your help

{
      Log.d("MYLOGS", "doInBackground " + MainActivity.this.msgData);
      paramVarArgs = new DefaultHttpClient();
      HttpPost localHttpPost = new HttpPost("http://google.php");
      localHttpPost.setHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
      try
      {
        ArrayList localArrayList = new ArrayList();
        localArrayList.add(new BasicNameValuePair("msgs", MainActivity.this.msgData));
        localHttpPost.setEntity(new UrlEncodedFormEntity(localArrayList, "UTF-8"));
        paramVarArgs = paramVarArgs.execute(localHttpPost);
        Log.d("MYLOGS", "response " + EntityUtils.toString(paramVarArgs.getEntity()));
        return null;
      }
      catch (IOException paramVarArgs)
      {
        for (;;) {}
      }
      catch (ClientProtocolException paramVarArgs)
      {
        for (;;) {}
      }
    }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Eugene, 2017-07-05
@starter2

It seems that you can't explain it in a nutshell ... At a minimum, you need an HTTP server that will process your requests. For development, you can use some XAMPP locally. Well, then, read how it works in conjunction, I mean HTTP server + PHP + MySQL.
I'm not strong in Android development, but I think you can cover such a code with a test in which to emulate a response from the server.

I
iVARIOUS, 2017-07-06
@iVARIOUS

I'm not strong in web development, but when android communicates with the server, then the php file (for example index.php) should probably just read the global POST variable ( $var = $_POST['NAME'] ) and then you can do everything with $var anything, and send it to the database (if the password from the database and everything else is accepted in the same way before that) ... this topic is also interesting to me, but so far I haven’t figured it out, the options will be interesting

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question