MonoDroid HttpWebRequest and WebClient unreliable?

I have many problems using WebRecests in MonoDroid and getting timeouts at random. My code works fine, and sometimes all requests just time out and don't work.

I checked that the web services used in my requests are not a problem.

Here is an example of some code that I can use to request some data from a web service using MonoDroid:

bool bolOk = false; HttpWebRequest request = (HttpWebRequest)WebRequest.Create ("http://www.website.com/service/"); request.Timeout = 20000; request.Credentials = gv_objCredentials; using (HttpWebResponse response = (HttpWebResponse)request.GetResponse ()) { bolOk = response.StatusCode == HttpStatusCode.OK; } 

As you can see, this is the main material. I am using code as above in another thread in the user interface using ThreadPool.QueueUserWorkItem or TaskFactory.

What I noticed is that if the requests start to count the time from my application, and I connect it to my computer, then debug the application from MonoDevelop, working without a chronometer. I'm not sure what this means. This is similar to testing web services from my computer using a browser on the same network as the phone. Web services always work without any problems.

What is the best way to create Web requests from MonoDroid?

How can I ensure that my requests are always successful and there will not be a timeout if the web service is working correctly?

+6
source share
2 answers

I had a question about Xamarin 4.2.6 and 4.2.8.

Thanks to Xamarin's support, they identified the problem and suggested that I target my assembly on armeabi-v7a, not armeabi, in the properties of my project (some problems with a multi-core processor are described here )

Depending on whether you plan to support multi-core processors or not, you should check out this post and you may have to manually edit it. Csproj file.

+2
source

There is a new version of Mono for Android (4.2.5), which fixes a number of errors using WebRequest and webRequestStream. You can check the release notes here: http://docs.xamarin.com/android/Releases/Mono_For_Android_4/Mono_for_Android_4.2.5

I suggest downloading the last bit and checking if it works. If not, report a bug and they will fix it in the next version of the product.

+1
source

Source: https://habr.com/ru/post/918522/


All Articles