How to perform a HTTP request ?

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


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

My first idea was to import java.net.*; 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.
Deniz
--~--~---------~--~----~------------~-------~--~----~



How to perform a HTTP request ?

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


 


Try this:

 http://www.exampledepot.com/egs/java.net/ReadFromURL.html 

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:

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

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com 
Warescription: Three Android Books, Plus Updates, $35/Year

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


Sponsored Links


Other Threads

1. How to access "shared data/settings" across multiple application? ContentProvider or SharedPreferences?

Suppose I have an application that runs functional testing and needs to
access the shared preferences. The function test extends
InstrumentationTestCase, but getting the shared prefs through the Context()
and targetContext() getters provided by the instrumentation doesn't seem to
let me be over writing the shared prefences values.

How would I go about doing that? Am I right in using the targetContext to do
that? Because it doesn't seem to be letting me.









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

2. is video recording supported on 1.5pre?

i have here an ADP1 with a Haykuro ROM in it. mostly it seems to work fine.

however, on calling setVideoEncoder(MediaRecorder.VideoEncoder.H264) 
however, i get app death with the following stack trace -

04-20 18:17:48.979: ERROR/AndroidRuntime(671): 
java.lang.RuntimeException: setVideoEncoder failed.
04-20 
18:17:48.979: ERROR/AndroidRuntime(671):     at 
android.media.MediaRecorder.setVideoEncoder(Native Method)
04-20 
18:17:48.979: ERROR/AndroidRuntime(671):     at 
com.particlebrand.uooo.android.CreateActivity.surfaceCreated(CreateActivity.java:115)
04-20 
18:17:48.979: ERROR/AndroidRuntime(671):     at 
android.view.SurfaceView.updateWindow(SurfaceView.java:352)
04-20 
18:17:48.979: ERROR/AndroidRuntime(671):     at 
android.view.SurfaceView.dispatchDraw(SurfaceView.java:259)

of course, it would be absolutely stellar if the error message 
explained just a little as to *WHY* the call failed.

should i hold off trying to record video for now?

(incidentally, it now seems like the phone won't launch my app at all 
now. attempts result in an immediate hang, with no UI at all. even a 
reboot doesn't free it up. what could cause this?)



-- 
jason.software.particle

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

3. Why RIL uses Local socket instead of binder ipc?

4. u-law PCM audio compression supported in 1.5?

5. Recording audio with 1.5 SDK

6. Views, ListViews and Adapters

7. New application - testing help wanted