Are you testing this on a 2.3.3 device?

On Aug 16, 4:37 am, Budi Wibowo <budiat...@gmail.com> wrote:
> I'm very new to android programming. I'm more used to c# programming.
>
> I'm having problem sending POST data to a PHP page using HttpURLConnection.
>
> i know that POST data has to be encoded in ascii and sent to the server in
> bytes format. this is what i did, and i have been unsuccessful. I tried
> following several web instruction to no avail.
> *URL url;
> HttpURLConnection conn;
> url=new URL("https://mysite.com/test.php";);
> conn=(HttpURLConnection)loginUrl.openConnection();
> conn.setRequestMethod("POST");
> String charset = "UTF-8";
> String qry =URLEncoder.encode("param1=hole&param2=ass",charse t);
> conn.setRequestProperty("Accept-Charset", charset);
> conn.setRequestProperty("Content-Type", "application/x-ww-form-urlencoded");
> conn.setRequestProperty("Content-Length",
> ""+Integer.toString(qry.getBytes().length));
> conn.setUseCaches(false);
> conn.setDoInput(true);
> conn.setDoOutput(true);
>
> //sendrequest
> DataOutputStream out= new DataOutputStream(conn.getOutputStream());
> txtResponse.setText(out.toString());
> out.writeBytes(qry);
> out.flush();
> **out.close();*
>
> I did not include the response code here, because it was running fine.
>
> in my PHP code, all i'm doing is spitting out the value of param1 and param
> 2. they all turned out empty.
>
> i tried modifying the parameter so that it will encode only the values, but
> not the key. however i still can't make it to work.
>
> i tried out.write(qry.getBytes);
> also tried out.write(("param1=1&param2=2").getBytes));
> nothing works!
>
> what am i doing wrong????

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to