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

前端 未结 8 648
深忆病人
深忆病人 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:06

    You need to do the following troubleshooting:

    1. Confirm that your 3G actually works. Open some standard websites like yahoo.
    2. Try to confirm if your 3G network can actually resolve the address that you have mentioned. If not you can try the IP address directly. If this step solves than your DNS is not able to resolve the address correctly.
    3. If the above two steps fail, restart the device, toggle airplane mode and retry again. Sometimes the 3G network works with reset.
    0 讨论(0)
  • 2021-01-04 07:14

    i had sometimes same problem ... why? because time out in my case ... depends quantity of bytes are you downloading .... Because did you try a simple call to ws?is it works? =>> time out.

    0 讨论(0)
  • 2021-01-04 07:16

    These errors often arise because the proxy failed to resolve a domain name into an address.

    This problem is entirely due to slow IP communication between back-end computers, possibly including the Web server. Only the people who set up the network at the site which hosts the Web server can fix this problem.

    0 讨论(0)
  • 2021-01-04 07:16

    I hope you are running operations on the user interface thread. Avoid that

    0 讨论(0)
  • 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");
        }
    }
    
    0 讨论(0)
  • 2021-01-04 07:17

    You could try to connect to your server via the web browser of your phone to see if the problem is within your application or if the problem is a 3G problem resolving/connecting to the address of your server.

    My guess is that you won't be able to connect either via a web browser.

    Where is hosted your web service? Should it be accessible from an external network ? You may be able to connect to your server via wifi if the server is in the same network.

    0 讨论(0)
提交回复
热议问题