Android: Can not send http post

后端 未结 4 695
没有蜡笔的小新
没有蜡笔的小新 2021-01-01 07:02

I\'ve been banging my head trying to figure out how to send a post method in Android. This is how my code look like:

public class HomeActivity extends Activi         


        
4条回答
  •  一整个雨季
    2021-01-01 07:45

    You can't call the web from the UI thread so you don't halt the app's UI, this blog post explains it with an example app using AndroidHttpClient: Official Android Dev Blog.

    Here is a quote:

    ...this is such a bad idea that the AndroidHttpClient does not allow itself to be started from the main thread. The above code will display "This thread forbids HTTP requests" error messages instead. Use the DefaultHttpClient instead if you really want to shoot yourself in the foot.

    So if you really want to run this on UI thread (bad idea, from personal experience and that blog post) then use DefaultHttpClient.

提交回复
热议问题