1. You want to setup a connection between the phone and a server, and you need to control both the input and the output. As a result, you use URL.openConnection(), with setDoInput() and setDoOutput() set to true:
URL url = new URL("https://blahblahblah.com");
URLConnection conn = url.openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
At some point you use both conn.getOutputStream() to write to the stream, then conn.getInputStream() to get the response.
2. You're doing an HTTPS connection. Some people report this happening on normal HTTP, but I've only seen it happen on HTTPS.
3. The first request goes through fine and dandy.
4. The second time you try to make the request, the connection doesn't send any data out and doesn't receive any data; it looks like it happens instantly. If you cast to an HttpURLConnection, conn.getResponseCode() returns -1 instead of anything meaningful.
In other words, every other request, the request fails outright. This is a noted bug in Android, but it isn't fixed yet in any released versions. Even when it's fixed, you'll still have to deal with this on older versions of Android.
There are a few workarounds. The first is to simply not use URLConnection; if you can find some way around it, avoid it. The second is to repeatedly make the same request until it works; it's a little too much of a hack for my tastes, but it'll work.
Then there's the third workaround, which I do not claim to understand why it fixes the issue but it does. Just set this setting when your application begins:
System.setProperty("http.keepAlive", "false");
Unfortunately this has some drawbacks (keep-alive is a good thing normally), but in comparison to mysteriously failed requests I'll ditch it.
When I initially commented, I clicked the “Notify me when new comments are added” checkbox and now each time a comment is added I get several emails with the same comment. Is there any way you can remove people from that service? Thanks.
ReplyDeleteAmazon Web Services Training in OMR , Chennai | Best AWS Training in OMR,Chennai
Amazon Web Services Training in Tambaram, Chennai|Best AWS Training in Tambaram, Chennai
This comment has been removed by the author.
ReplyDeleteWell Said, you have furnished the right information that will be useful to anyone at all time. Thanks for sharing your Ideas.
ReplyDeleteangularjs Training in chennai
angularjs Training in chennai
angularjs-Training in tambaram
angularjs-Training in sholinganallur
I am sure this post has helped me save many hours of browsing other related posts just to find what I was looking for. Many thanks!
ReplyDeleteonline Python certification course | python training in OMR | Python training course in Chennai
Excellant post!!!. The strategy you have posted on this technology helped me to get into the next level and had lot of information in it.
ReplyDeleteDevops training in indira-nagar
A very nice guide. I will definitely follow these tips. Thank you for sharing such detailed article. I am learning a lot from you.
ReplyDeleterpa training in electronic-city | rpa training in btm | rpa training in marathahalli | rpa training in pune
It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
ReplyDeleteJava training in Indira nagar | Java training in Rajaji nagar
Java training in Marathahalli | Java training in Btm layout
All the points you described so beautiful. Every time i read your i blog and i am so surprised that how you can write so well.
ReplyDeleteData Science course in kalyan nagar | Data Science course in OMR
Data Science course in chennai | Data science course in velachery
Data science course in jaya nagar | Data science training in tambaram
I have been meaning to write something like this on my website and you have given me an idea. Cheers.
ReplyDeletedevops online training
aws online training
data science with python online training
data science online training
rpa online training
I am really very happy to find this particular site. I just wanted to say thank you for this huge read!! I absolutely enjoying every petite bit of it and I have you bookmarked to test out new substance you post.
ReplyDeleteMicrosoft Azure online training
Selenium online training
Java online training
Python online training
uipath online training
Excellent Article. Thanks Admin
ReplyDeleteDevOps Training in Chennai
DevOps Certification in Chennai
very nice...
ReplyDeletebrunei darussalam web hosting
costa rica web hosting
costa rica web hosting
hong kong web hosting
jordan web hosting
turkey web hosting
very nice...
ReplyDeletegibraltar web hosting
iceland web hosting
lebanon web hosting
lithuania shared web hosting
inplant training in chennai
nice..
ReplyDeletehosting
india hosting
india web hosting
iran web hosting
technology 11 great image sites like imgur hosting
final year project dotnet server hacking what is web hosting
macao web hosting
inplant training in chennai
inplant training in chennai
inplant training in chennai for it.php
inplant training in chennai
ReplyDeleteinplant training in chennai
inplant training in chennai for it.php
chile web hosting
colombia web hosting
croatia web hosting
cyprus web hosting
bahrain web hosting
india web hosting
iran web hosting
Excellent post...
ReplyDeleteinplant training in chennai
inplant training in chennai
inplant training in chennai for it
Australia hosting
mexico web hosting
moldova web hosting
albania web hosting
andorra hosting
australia web hosting
denmark web hosting
Excellent post.....
ReplyDeleter programming training in chennai
internship in bangalore for ece students
inplant training for mechanical engineering students
summer internships in hyderabad for cse students 2019
final year project ideas for information technology
bba internship certificate
internship in bangalore for ece
internship for cse students in hyderabad
summer training for ece students after second year
robotics courses in chennai
Excellent post.....
ReplyDeleter programming training in chennai
internship in bangalore for ece students
inplant training for mechanical engineering students
summer internships in hyderabad for cse students 2019
final year project ideas for information technology
bba internship certificate
internship in bangalore for ece
internship for cse students in hyderabad
summer training for ece students after second year
robotics courses in chennai
excellent blogs.....!!!
ReplyDeletechile web hosting
colombia web hosting
croatia web hosting
cyprus web hosting
bahrain web hosting
india web hosting
iran web hosting
kazakhstan web hosting
korea web hosting
moldova web hosting
nice...
ReplyDeleteslovakia web hosting
timor lestes hosting
egypt hosting
egypt web hosting
ghana hosting
iceland hosting
italy shared web hosting
jamaica web hosting
kenya hosting
kuwait web hosting
very good.....
ReplyDeleteinternship in bangalore for cse students
internship for aerospace engineering students in india
core companies in coimbatore for ece internship
paid internship in pune for computer engineering students
automobile internship in chennai
internship in chennai for eee with stipend
internship for bca students
dotnet training in chennai
aeronautical engineering internship
inplant training for ece students
nice post...
ReplyDeletepython training in chennai
internships in hyderabad for cse 2nd year students
online inplant training
internships for aeronautical engineering students
kaashiv infotech internship review
report of summer internship in c++
cse internships in hyderabad
python internship
internship for civil engineering students in chennai
robotics course in chennai
nice.....it is use full...
ReplyDeleteaeronautical internship in india
free internship in chennai for mechanical engineering student
architectural firms in chennai for internship
internship in coimbatore for eee
online internships for cse students
mechanical internship certificate
inplant training report
internships in hyderabad for cse
internship for mba students in chennai
internship in trichy for cse
Great Blog. Thnaks.
ReplyDeleteSAP Training in Chennai
Java Training in Chennai
Software Testing Training in Chennai
.Net Training in Chennai
Hardware and Networking Training in Chennai
AWS Training in Chennai
Azure Training in Chennai
Selenium Training in Chennai
QTP Training in Chennai
Android Training in Chennai
I've been looking for something like Dubai to Pakistan Cargo to help with a research Cargo Services I've been working on.
ReplyDelete