0

I am not able to access the post parameters i'm sending from an android device. From code examples I have been looking at, I'm not sure what I am doing wrong -- any help is appreciated.

Here is my android code:

        URL t_url = new URL(urlStr);
        HttpsURLConnection con = (HttpsURLConnection) t_url.openConnection();

        //Create SSL con
        SSLContext sc;
        sc = SSLContext.getInstance("TLS");
        sc.init(null, null, new java.security.SecureRandom());
        con.setSSLSocketFactory(sc.getSocketFactory());

        con.setReadTimeout(10000);
        con.setConnectTimeout(10000);
        con.setRequestMethod("POST");
        con.setDoOutput(true);
        con.setInstanceFollowRedirects(false);
        con.setRequestProperty("phone_number", mPhone_number);
        con.setUseCaches(false);

        con.connect();

As you can see, I am sending a request property with a phone number.

To try to grab this in PHP, I use this code:

$phone_num = $POST_['phone_number'];

To test to see if this is successful, I use:

file_put_contents($file, "Entry: " . $phone_num . "\n", FILE_APPEND | LOCK_EX);

My log file is coming up empty, so my guess is that I am not getting the post data correctly from the android device.

If you have any questions about my code or what I am trying to do, please ask and I will elaborate.

Solved my issue by sending them as JSON!

  • Okay I'm not a PHP expert but: With `setRequestProperty` you set a header field _Sets the value of the specified request header field._ but on PHP side you try to read a post body. Read this http://stackoverflow.com/questions/20020902/android-httpurlconnection-how-to-set-post-data-in-http-body – Ralph Bergmann May 16 '16 at 20:36
  • Thanks @RalphBergmann, I tried this method before, but was unable to figure out how to grab the string that is sent in my php code. Do you know if that code you sent should be working with my php code? – OxenFreeHorchata May 16 '16 at 20:50
  • I'm sorry but I have no experiences with PHP :-( – Ralph Bergmann May 16 '16 at 20:56

0 Answers0