How to perform a HTTP request ?

by binklee » Sun, 15 Mar 2009 06:47:14 GMT

Sponsored Links
I'm trying to perform a HTTP request and to read the answer.

My first idea was to import*; and to use :

URL url = new URL(myUrl);
String answer = (String)url.getContent(); // !!!  produce an error in
Android !

After some research in the group, I am confused on what should I do.
Should I use :

org.apache.http                                         or
org.apache.commons.httpclient.HttpClient         // <--- is it
officially supported by android?

and how to implement it?

Thank you for your help.

How to perform a HTTP request ?

by Mark Murphy » Sun, 15 Mar 2009 08:11:55 GMT


Try this: 

Also, make sure you have the INTERNET permission declared in your
AndroidManifest.xml file.

Android currently incorporates org.apache.http.*. Previously, it used an
earlier version of the Apache code which was in the
org.apache.commons.httpclient.* namespace.

Examples of using org.apache.http.* can be found at: 

Mark Murphy (a Commons Guy) 
Warescription: Three Android Books, Plus Updates, $35/Year


Sponsored Links

Other Threads

1. ADC2 [tools] Mezzofanti - Augmented reality through text recognition

Great work.
I previously had a similar idea for an application for ADC2 using OCR
engine but no one figured out how to incorporate the Tesseract engine.

Btw, is the apk available for download somewhere?



2. Need help with MediaStore

Hi guys,

I am trying to make an application which will upload pictures to a
website. I need to let the user browse through the pictures they want
to upload and select them. However, when I try to use the MediaStore I
always get an empty cursor.

I created an SD CARD image and used that with the emulator. I know one
image exists in /sdcard/media. I copied it using an image manipulation
tool (winimage). And, I can see the image when I use the command "ls /
sdcard/media" in the terminal application of the phone.

The code I am using is this :

                // Here we set up a string array of the thumbnail ID column we 
to get back
                String [] proj={MediaStore.Images.Thumbnails._ID};
                // Now we create the cursor pointing to the external thumbnail 
                cursor = managedQuery
( MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
                                proj, // Which columns to return
                                null,       // WHERE clause; which rows to 
return (all rows)
                                null,       // WHERE clause selection arguments 
                                null); // Order-by clause (ascending by name)
                // We now get the column index of the thumbnail id
                Log.i(tag, "size: ");
                Log.i(tag, "size: "+cursor.getCount());

Am I missing something here?

Thanks in advance for the help,


3. Error generating final archive ... post Apple Software Update

4. SDCARD images/audio/video not reflected in gallery.

5. Problem in Listview with Checkbox

6. getting crash stack....

7. Activity.isForeground()