Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
HttpClient and POST requests
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  7 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
fala70  
View profile  
 More options Nov 22 2008, 9:39 am
From: fala70 <fal...@gmail.com>
Date: Sat, 22 Nov 2008 06:39:07 -0800 (PST)
Local: Sat, Nov 22 2008 9:39 am
Subject: HttpClient and POST requests
Hi, I've a problem to translate follow code to org.apache.http.*;

           OutputStream pos = new OutputStream();
            pos.writeShort(Const.INVOCATION_CODE);
            pos.writeInt(requestId);
            pos.writeString(nickname);
            pos.writeString(password);

           conn = (HttpConnection) Connector.open(url,
Connector.READ_WRITE);
            conn.setRequestMethod(HttpConnection.POST);
            conn.setRequestProperty("Content-Type", "application/octet-
stream");
            conn.setRequestProperty("Accept", "application/octet-stream");

            if(sessionCookie == null)
            {
                conn.setRequestProperty("version", "???");
            }
            else
            {
                conn.setRequestProperty("cookie", sessionCookie);
            }

            // Getting the output stream may flush the headers
            os = conn.openDataOutputStream();
            os.write(pos.getBytes());
            os.close();

start connection I must use :
                HttpClient conn = new DefaultHttpClient();
                HttpPost httppost = new HttpPost(url);

but I've difficult to understand what must I use to set the request
proprieties (setRequestProperty) and use an OutputStream to send my
requests

thanks


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mark Murphy  
View profile  
 More options Nov 22 2008, 9:46 am
From: Mark Murphy <mmur...@commonsware.com>
Date: Sat, 22 Nov 2008 09:46:47 -0500
Local: Sat, Nov 22 2008 9:46 am
Subject: Re: [android-beginners] HttpClient and POST requests

fala70 wrote:
> Hi, I've a problem to translate follow code to org.apache.http.*;

Questions related to the Apache HTTPComponents are best asked of the
Apache HTTPComponents team:

http://hc.apache.org/

--
Mark Murphy (a Commons Guy)
http://commonsware.com
_The Busy Coder's Guide to Android Development_ Version 1.4 Published!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Adam Connors  
View profile  
 More options Nov 22 2008, 11:08 am
From: "Adam Connors" <adamconn...@gmail.com>
Date: Sat, 22 Nov 2008 16:08:33 +0000
Local: Sat, Nov 22 2008 11:08 am
Subject: Re: [android-beginners] HttpClient and POST requests

Hope this is useful:

   88:     HttpPost post = null;
   89:     post = new HttpPost(url);
   91:     post.addHeader("Content-Type", "multipart/related;
boundary=\"END_OF_PART\"");
   92:     post.addHeader("MIME-version", "1.0");
   93:
  116:
  117:     HttpEntity body = new ByteArrayEntity(bodyBytes);
  118:     post.setEntity(body);
  121:     HttpResponse resp = uploadClient.execute(post);

Instead of ByteArrayEntity sounds like you want InputStreamEntity or such
like...

*BUT: *In my experience using an InputStreamEntity is bad because over flaky
connections the HttpClient sometimes attempts to resend packets and the
InputStreamEntity is "not-repeatable"... (You'll get periodic
EntityNotRepeatable errors). Which is why I switched to using a
ByteArrayEntity as above which seems to work slightly better for large
streams.

Hope that answers your question,

Best,

Adam.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
fala70  
View profile  
 More options Nov 22 2008, 6:24 pm
From: fala70 <fal...@gmail.com>
Date: Sat, 22 Nov 2008 15:24:18 -0800 (PST)
Local: Sat, Nov 22 2008 6:24 pm
Subject: Re: HttpClient and POST requests
thanks Adam, for your answer. I tried your instructions but when I
call the execute I receive an IOException. Follow the stack log. Any
idea ???

Also I tried to use the same Header, but without success.
                httppost.addHeader("Content-Type", "application/octet-
stream");
                httppost.addHeader("Accept", "application/octet-stream");

stack log.

11-22 23:05:43.834: WARN/System.err(478): java.net.SocketException:
unknown error
11-22 23:05:43.843: WARN/System.err(478):     at
org.apache.harmony.luni.platform.OSNetworkSystem.createSocketImpl
(Native Method)
11-22 23:05:43.853: WARN/System.err(478):     at
org.apache.harmony.luni.platform.OSNetworkSystem.createSocket
(OSNetworkSystem.java:79)
11-22 23:05:43.853: WARN/System.err(478):     at
org.apache.harmony.luni.net.PlainSocketImpl2.create
(PlainSocketImpl2.java:59)
11-22 23:05:43.863: WARN/System.err(478):     at
java.net.Socket.checkClosedAndCreate(Socket.java:763)
11-22 23:05:43.873: WARN/System.err(478):     at
java.net.Socket.connect(Socket.java:910)
11-22 23:05:43.873: WARN/System.err(478):     at
org.apache.http.conn.scheme.PlainSocketFactory.connectSocket
(PlainSocketFactory.java:117)
11-22 23:05:43.882: WARN/System.err(478):     at
org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection
(DefaultClientConnectionOperator.java:129)
11-22 23:05:43.892: WARN/System.err(478):     at
org.apache.http.impl.conn.AbstractPoolEntry.open
(AbstractPoolEntry.java:164)
11-22 23:05:43.892: WARN/System.err(478):     at
org.apache.http.impl.conn.AbstractPooledConnAdapter.open
(AbstractPooledConnAdapter.java:119)
11-22 23:05:43.904: WARN/System.err(478):     at
org.apache.http.impl.client.DefaultRequestDirector.execute
(DefaultRequestDirector.java:348)
11-22 23:05:43.914: WARN/System.err(478):     at
org.apache.http.impl.client.AbstractHttpClient.execute
(AbstractHttpClient.java:555)
11-22 23:05:43.914: WARN/System.err(478):     at
org.apache.http.impl.client.AbstractHttpClient.execute
(AbstractHttpClient.java:487)
11-22 23:05:43.923: WARN/System.err(478):     at
org.apache.http.impl.client.AbstractHttpClient.execute
(AbstractHttpClient.java:465)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Adam Connors  
View profile  
 More options Nov 23 2008, 4:36 am
From: "Adam Connors" <adamconn...@gmail.com>
Date: Sun, 23 Nov 2008 09:36:31 +0000
Local: Sun, Nov 23 2008 4:36 am
Subject: Re: [android-beginners] Re: HttpClient and POST requests
Best guess... Do you have the INTERNET permission correctly declared
in your manifest...?

On 11/22/08, fala70 <fal...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
fala70  
View profile  
 More options Nov 23 2008, 9:09 am
From: fala70 <fal...@gmail.com>
Date: Sun, 23 Nov 2008 06:09:35 -0800 (PST)
Local: Sun, Nov 23 2008 9:09 am
Subject: Re: HttpClient and POST requests
Yeah.... Thanks Adam now work

On 23 Nov, 10:36, "Adam Connors" <adamconn...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
agal  
View profile  
 More options Dec 16 2008, 11:45 pm
From: agal <allgreekandla...@gmail.com>
Date: Tue, 16 Dec 2008 20:45:37 -0800 (PST)
Local: Tues, Dec 16 2008 11:45 pm
Subject: Re: HttpClient and POST requests
Hi,

I would like to know how to set headers in an Http Post request. This
is what I tried:
...
HttpPost postMethod=new HttpPost(posturl);
postMethod.addHeader("Content-Type", "something");
postMethod.addHeader("Content-Length", "length of content");
String requestBody = "some text";
postMethod.setEntity(new StringEntity(requestBody));
...

The server that I'm posting to is rejecting this request because it's
not able to retrieve the content length.

Could anyone help me with this?

Thanks.

On Nov 23, 7:09 pm, fala70 <fal...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »