HttpClient and POST requests

by fala70 » Sat, 22 Nov 2008 22:39:17 GMT


Sponsored Links
 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
--~--~---------~--~----~------------~-------~--~----~



HttpClient and POST requests

by Mark Murphy » Sat, 22 Nov 2008 22:47:04 GMT


 


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!

--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


HttpClient and POST requests

by Adam Connors » Sun, 23 Nov 2008 00:08:47 GMT


 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.





--~--~---------~--~----~------------~-------~--~----~



HttpClient and POST requests

by fala70 » Sun, 23 Nov 2008 04:45:33 GMT


 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

--~--~---------~--~----~------------~-------~--~----~



HttpClient and POST requests

by fala70 » Sun, 23 Nov 2008 04:45:40 GMT


 I am using android-sdk-windows-1.0_r1 and need to translate a snip
code to use over android G1. Old is that:

           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();


I must used org.apache.http.client.HttpClient; package. The new
connection type will be:
                HttpClient conn = new DefaultHttpClient();
                HttpPost httppost = new HttpPost(url);

but I didn't understand what use to translate setRequestProperty, for
set all my prorprieties.

thanks

--~--~---------~--~----~------------~-------~--~----~



HttpClient and POST requests

by fala70 » Sun, 23 Nov 2008 07:24:32 GMT


 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)

--~--~---------~--~----~------------~-------~--~----~



HttpClient and POST requests

by Adam Connors » Sun, 23 Nov 2008 17:36:38 GMT


 Best guess... Do you have the INTERNET permission correctly declared
in your manifest...?




--~--~---------~--~----~------------~-------~--~----~



HttpClient and POST requests

by Guillaume Perrot » Sun, 23 Nov 2008 19:34:03 GMT


  http://hc.apache.org/httpcomponents-client/examples.html 



--~--~---------~--~----~------------~-------~--~----~



HttpClient and POST requests

by fala70 » Sun, 23 Nov 2008 22:09:47 GMT


 Yeah.... Thanks Adam now work




--~--~---------~--~----~------------~-------~--~----~



HttpClient and POST requests

by Christine » Mon, 24 Nov 2008 05:56:16 GMT


 The examples that Guillaume points you to cover most of what you want
to do in a POST.
What they don't cover is multipart mime messages and setting mime
types. With "application/octet" as the mime type you should be ok with
the examples. Otherwise, do have a look at HttpMime.

On Nov 23, 12:33pm, Guillaume Perrot <[EMAIL PROTECTED]>



--~--~---------~--~----~------------~-------~--~----~



HttpClient and POST requests

by agal » Thu, 18 Dec 2008 01:26:35 GMT


 i,

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:09pm, fala70 <fal...@gmail.com> wrote:

--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Problem related to multiple Screen Support

Hi,

I am trying to develop an app for which I want multiple screen
support. I have read the Android article on Best practices for
Multiple Screen Support. As per the article we have to follow 3
important things
1. Mention support for different screen sizes(large, medium and small)
and any density in AndroidManifest.xml.
2. Place images of 3 dpi's (120, 160, 240) in 3 folders res/ldpi, res/
mdpi and res/hdpi.
3. In layout's the dimension should be mentioned in "dip" units. Then
Android will take care of the scaling on its own.

I have implemented all these points in my project. The images are
picked up correctly from the appropriate folders. But the arrangements
of the controls in not same.
e.g. I ran the app on three emulators
1. Resolution 240*320 dpi 120.
2. Resolution 240*320 dpi 160.
3. Resolution 240*320 dpi 240.
(All the emulator have same resolution but different density. )

The problem is the position of the controls is not same on all the
three emulator. As per my understanding if the
android:layout_marginLeft and android:layout_marginTop are mentioned
in "dip" then this problem should not occur. As the density of the
emulator increases the controls get placed more towards the right.

Is it necessary that i provide layouts for all combinations of
dimensions and density i.e. in layout-small, layout-large, layout-
medium, layout-long,layout-notlong?

Am I missing some important point? Any help will be great.
Thanks.

-- 

2. Drawing a marker when user touch the map

Hi, I'm trying to develop an Android app that will draw a mark on the
map when the user touch the map. I've been searching around the web
but can't find any example or tutorials on it. Can anyone tell me how
can i go about doing it? Thanks in advance.

-- 

3. How to get a string from a website, and show the string on my android app. ?

4. issue with Edit Text

5. Calling wipeData from a service

6. UI -using the setText() method ?

7. Samsung Adopts ARM鈥檚 Next Generation Mali-T604 GPU