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

帅比萌擦擦* 提交于 2019-11-30 17:36:38

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.

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.

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.

Tobiel

It seems you are having the same issue i had. I spend a lot of time debugging my code but this question solve all my issues-> Your server is accessible from the public internet? android why sending information to server works with WIFI only?

  • Basically in some remote area 3G connectivity is not as much speed like wifi. Try to check your 3G is providing you sequence of data connection. If not, then it fails to "post"

  • Next, you have to check the posting time limit. If you take too much time to post,its common to get error while posting. Try to give some maximum time limit in-order to post huge data

  • Instead of using asyn, try to use Handlers or service class to upload something in background.

Since i'm beginner to android,this are all the options in my mind. It will be more helpful for us if something beyond to this.

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

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.

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");
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!