Kiran,

I think you are looking for this:
http://bytes.com/topic/java/answers/720825-how-build-http-post-request-java

Cheers

On Feb 27, 10:57 pm, Kiran <kiran.ka...@gmail.com> wrote:
> Hi All,
>
> I am trying to send a HTTP POST command from Android Device A to
> Android Device B.  Device B is running a simple web server.  The code
> that I am using for the webserver is 
> here:http://code.google.com/p/android-webserver/
>
> I am adding functionality to the code for it to process HTTP POST
> commands, currently it only supports HTTP GET.
>
> In order to send my HTTP POST command from Device A, I do the
> following:
>
> HttpClient httpclient = new DefaultHttpClient();
> HttpPost httppost = new HttpPost(url);
>
> try {
>     List<NameValuePair> pairs = new ArrayList<NameValuePair>();
>     pairs.add(new BasicNameValuePair("key1", "value1"));
>     pairs.add(new BasicNameValuePair("key2", "value2"));
>     httppost.setEntity(new UrlEncodedFormEntity(pairs));
>
>     HttpResponse httpresponse = httpclient.execute(httppost);}
>
> catch (IOException e) {
>     e.printStackTrace();
>
> }
>
> In Device B, I have opened an input stream from a socket in Java.  I
> am printing out all the lines that I am receiving via the socket.  The
> code looks as follows:
>
> try {
>     in = new BufferedReader(new
> InputStreamReader(toClient.getInputStream()));
>
>     // Receive data
>     while (true) {
>         String s = in.readLine().trim();
>         Log.i(TAG, "line=" + s);
>         if(s==null) {
>             break;
>         }
>     }
>
> }
>
> When I run the webserver on Device B and run the snippet of code
> posted above on Device A, the only output of the webserver that I get
> is:
> line=POST / HTTP/1.1
> line=Content-Length: 23
>
> I am wondering where the HTTP POST data is?  Shouldn't I be able to
> see it in the printout?  It seems like I am only seeing the HTTP
> header.
>
> Thanks in advance for your help,
> K

-- 
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