[android-developers] Re: HTTP POST to Web Server running on Android Device
line=POST / HTTP/1.1 line=Content-Length: 23 No you would see: line=POST / HTTP/1.1 line=Content-Length: 23 line=0 if a null was returned. But a null is never returned. Still your loop ends as instead an exception is trown. You did not see that because the catch does nothing. Add a Log.i there and you will see. You modified the original code which checked for an empty line. Take the original code again. Add a check for the Content-Lengh: line and decode the contentlength. (in your example 23) Then outside the loop do something like: [code] if ( contentlength 0 ){ char [] buffer = new char[contentlength]; int nread = in.read (buffer, 0, contentlength); String Parameters = new String( buffer); // well you should check nread == contentlength } [/code] I am wondering where the HTTP POST data is? That just follows the empty line. But as that data is not ended with a newline in.readLine() cannot be used. -- 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
[android-developers] Re: HTTP POST to Web Server running on Android Device
line=POST / HTTP/1.1 line=Content-Length: 23 No, you would see: line=POST / HTTP/1.1 line=Content-Length: 23 line=0 if a null was returned. But a null is never returned. Still your loop ends as instead an exception is trown which you did not see because the catch statement is empty. Add a Log.i there and you will see. You modified the original code where the loops ends at the first empty line. Take the original code again en check for the Content-Length line. Parse out the value for contentlength; After the loop add following code [code] if ( contentlength 0 ) { char [] buffer = new char[contentlength]; int nread = in.read (buffer, 0, contentlength); String Parameters = new String( buffer); // well you should check if nread equals contentlength } [/code] I am wondering where the HTTP POST data is? That just follows the empty line. But as this post data is not terminated with a newline character in.readLine() cannot be used. -- 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
[android-developers] Re: HTTP POST to Web Server running on Android Device
line=POST / HTTP/1.1 line=Content-Length: 23 No, you would see: line=POST / HTTP/1.1 line=Content-Length: 23 line=0 if a null was returned. But a null is never returned. Still your loop ends as instead an exception is trown which you did not see because the catch statement is empty. Add a Log.i there and you will see. You modified the original code where the loops ends at the first empty line. Take the original code again en check for the Content-Length line. Parse out the value for contentlength; After the loop add following code if ( contentlength 0 ) { char [] buffer = new char[contentlength]; int nread = in.read (buffer, 0, contentlength); String Parameters = new String( buffer); // well you should check if nread equals contentlength } I am wondering where the HTTP POST data is? That just follows the empty line. But as this post data is not terminated with a newline character in.readLine() cannot be used. -- 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
[android-developers] Re: HTTP POST to Web Server running on Android Device
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 { ListNameValuePair pairs = new ArrayListNameValuePair(); 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