No, you should be using that class. Use
org.apache.http.impl.client.DefaultHttpClient (or other applicable
client class in that package). org.apache.http.impl.* is also
undocumented, but *should* have been and will be in the next release
of the SDK.

However, you *should not* be doing http request in your main UI
thread. Create a new Thread to do the request in and return the
results to the UI thread when completed.

Snem, if you are also using this anroid.net.AndroidHttpClient class,
please switch as well.

Cheers,
Justin
Android Team @ Google

On Aug 28, 10:56 am, rajesh <[EMAIL PROTECTED]> wrote:
> Also the require permission is available in manifest file.
>
> On Aug 28, 10:55 pm, rajesh <[EMAIL PROTECTED]> wrote:
>
> > public class AndroidHttpActivity extends Activity {
> >         private Context context;
>
> >          /** Called when the activity is first created. */
> >   @Override
> >   public void onCreate(Bundle savedInstanceState)  {
> >         super.onCreate(savedInstanceState);
> >         setContentView(R.layout.http);
> >         context = this;
> >                 Button processBtn = (Button) 
> > this.findViewById(R.id.process);
> >         processBtn.setOnClickListener(new View.OnClickListener() {
> >         public void onClick(View v) {
> >             AndroidHttpClient client =
> > AndroidHttpClient.newInstance("test");
> >                 HttpGet post = new HttpGet("http://www.google.com";);
> >                 try {
> >                                 HttpResponse res = client.execute(post);
> >                         } catch (IOException e) {
> >                                 // TODO Auto-generated catch block
> >                                 e.printStackTrace();
> >                         }
> >         }
> >       });
> >   }
>
> > }
>
> > I am too getting the same error.
>
> > Secondly I don't find AndroidHttpClient in the documented list. Can we
> > use this API. If not which API should we use for HTTP Connetion
>
> > On Aug 28, 9:39 pm, "Justin (Google Employee)" <[EMAIL PROTECTED]>
> > wrote:
>
> > > There's not enough information here to really know what you're doing,
> > > can you post your code?
>
> > > Cheers,
> > > Justin
> > > Android Team @ Google
>
> > > On Aug 28, 6:47 am, Snem <[EMAIL PROTECTED]> wrote:
>
> > > > Put in a thread (Handler handler = new android.os.Handler();
> > > > handler.post(httpHandler);)
> > > > <uses-permission android:name="android.permission.INTERNET" /> added
> > > > to manifest file
>
> > > > Still error "java.lang.RuntimeException: This thread forbids HTTP
> > > > requests"
>
> > > > logcat log:
>
> > > > W/System.err(  484): java.lang.RuntimeException: This thread forbids
> > > > HTTP requests
> > > > W/System.err(  484):    at android.net.http.AndroidHttpClient
> > > > $1.process(AndroidHttpClient.java:79)
> > > > W/System.err(  484):    at
> > > > org.apache.http.protocol.BasicHttpProcessor.process(BasicHttpProcessor.java­­:
> > > > 290)
> > > > W/System.err(  484):    at
> > > > org.apache.http.protocol.HttpRequestExecutor.preProcess(HttpRequestExecutor­­.java:
> > > > 160)
> > > > W/System.err(  484):    at
> > > > org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDi­­rector.java:
> > > > 390)
> > > > W/System.err(  484):    at
> > > > org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.j­­ava:
> > > > 555)
> > > > W/System.err(  484):    at
> > > > org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.j­­ava:
> > > > 487)
> > > > W/System.err(  484):    at
> > > > org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.j­­ava:
> > > > 465)
> > > > W/System.err(  484):    at
> > > > android.net.http.AndroidHttpClient.execute(AndroidHttpClient.java:234)
> > > > W/System.err(  484):    at
> > > > com.android.test.HttpHandler.executeGet(HttpHandler.java:27)
> > > > W/System.err(  484):    at
> > > > com.android.test.HttpHandler.run(HttpHandler.java:45)
>
> > > > W/System.err(  484):    at
> > > > android.os.Handler.handleCallback(Handler.java:542)
> > > > W/System.err(  484):    at
> > > > android.os.Handler.dispatchMessage(Handler.java:86)
> > > > W/System.err(  484):    at android.os.Looper.loop(Looper.java:123)
> > > > W/System.err(  484):    at
> > > > android.app.ActivityThread.main(ActivityThread.java:3708)
> > > > W/System.err(  484):    at
> > > > java.lang.reflect.Method.invokeNative(Native Method)
> > > > W/System.err(  484):    at java.lang.reflect.Method.invoke(Method.java:
> > > > 492)
> > > > W/System.err(  484):    at com.android.internal.os.ZygoteInit
> > > > $MethodAndArgsCaller.run(ZygoteInit.java:734)
> > > > W/System.err(  484):    at
> > > > com.android.internal.os.ZygoteInit.main(ZygoteInit.java:492)
> > > > W/System.err(  484):    at dalvik.system.NativeStart.main(Native
> > > > Method)
>
> > > > Regards
>
> > > > On 28 Ago, 00:35, "Justin (Google Employee)" <[EMAIL PROTECTED]> wrote:
>
> > > > > Can you provide the output from logcat? Is <uses-permission
> > > > > android:name="android.permission.INTERNET" /> in your manifest file?
>
> > > > > Cheers,
> > > > > Justin
> > > > > Android Team @ Google
>
> > > > > On Aug 27, 12:51 pm, androidETuser <[EMAIL PROTECTED]> wrote:
>
> > > > > > I am trying to make HTTP requests thru android APis. But I am 
> > > > > > getting
> > > > > > some error.
>
> > > > > > Did any one saw this error before? Can someone help me out here?
>
> > > > > > Here is the code I am running. This code executed when the sub
> > > > > > activitilty is completed and the callback is called.
>
> > > > > >     protected void onActivityResult(int requestCode, int resultCode,
> > > > > > Intent intent) {
> > > > > >         super.onActivityResult(requestCode, resultCode, intent);
>
> > > > > >         Bundle extras = intent.getExtras();
>
> > > > > >                String symbol = extras.getString("Symbol");
>
> > > > > >               String lastPrc = getLastPrice(symbol);
> > > > > >     }
>
> > > > > >     private String getLastPrice (final String symbol) {
> > > > > >         String  response = new String();
> > > > > >         String errMsg = new String();
> > > > > >         errMsg = "test";
>
> > > > > >         try {
>
> > > > > >                 AndroidHttpClient httpClient =
> > > > > > AndroidHttpClient.newInstance("Etrade");
>
> > > > > >                 HttpGet authGet = new HttpGet( 
> > > > > > "https://us.etrade.com/e/t/invest/
> > > > > > flash?type=EQ&sym=" + symbol);
> > > > > >                 HttpResponse resp = httpClient.execute(authGet);
> > > > > >                  response = resp.toString();
> > > > > >             System.out.println("actual response is " + response);
> > > > > >         } catch(Exception e) {
> > > > > >                 errMsg = e.getMessage();
>
> > > > > >                 System.out.println("actual error msg is " + errMsg);
> > > > > >                 e.printStackTrace();
> > > > > >         }
> > > > > >         return response;
> > > > > >     }
>
> > > > > > This line is thrwoing errors.
> > > > > >         httpClient.execute(authGet);
>
> > > > > > And the error message is "This thread forbids HTTP requests".
>
> > > > > > Thanks,
> > > > > > Navin- Hide quoted text -
>
> > > - Show quoted text -- Hide quoted text -
>
> > - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
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
[EMAIL PROTECTED]
Announcing the new Android 0.9 SDK beta!
http://android-developers.blogspot.com/2008/08/announcing-beta-release-of-android-sdk.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to