AsyncTask HttpPost execute fails on 3G, but works on Wifi

前端 未结 8 707
深忆病人
深忆病人 2021-01-04 06:39

I need to do a Http post of some strings to a web service. I am using KSoap.

@Override
protected JSONObject doInBackground(JSONObject... params) {
    String         


        
8条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-04 07:16

    For Android 2.3 (Gingerbread) and higher, the HttpUrlConnection is recommended instead of the HttpClient. See this Android team post: http://android-developers.blogspot.com/2011/09/androids-http-clients.html

    It's possible that HttpClient is buggy on the device you're using and there are issues sending data over 3G.

    Also, be sure to call this method before doing an HTTP request when using the HttpURLConnection:

    private void disableConnectionReuseIfNecessary() {
        // HTTP connection reuse which was buggy pre-froyo
        if (Integer.parseInt(Build.VERSION.SDK) < Build.VERSION_CODES.FROYO) {
            System.setProperty("http.keepAlive", "false");
        }
    }
    

提交回复
热议问题