httpurlconnection

Uploading file in a https url in post method - java.io.IOException: Error writing to server - Java

谁说我不能喝 提交于 2020-01-15 23:41:14
问题 I have to upload a binary image file to the server using multi-part, I open the connection to the https url and write diretly to to the outputstream. I have tried the SSLSocket, apache http client, but in all ways I get the error message, java.io.IOException: Error writing to server. I have to write post params with the multi-part binary file. The code is given below, where am I failing to see the mistake in this code below? And, I have given the sample data to write the data to the

Where check/set timeout when java.net.UnknownHostException is thrown?

岁酱吖の 提交于 2020-01-15 03:01:50
问题 Where check/set timeout when java.net.UnknownHostException is thrown? Occasionally my code tries to connect to a non-existing location and throws java.net.UnknownHostException what is acceptable case in my app. The problem I have is that it takes roughly about 20sec before the exception is thrown and it slows down the whole application. The webserver version is Tomcat 7.0.37. I have tried change timeout settings (to 2sec) in the server.xml for following connectors: Connector port="8009"

Inconsistent HttpUrlConnection behaviours on Android - how to debug?

社会主义新天地 提交于 2020-01-14 10:22:48
问题 I have a weird problem: Implementing an interface to a webserver in my Android App, I connect to it using a HttpsUrlConnection. The connection uses additional HTTP Basic authorization (using setRequestProperty ), but otherwise is a plain GET request over HTTPS. It works perfectly fine using it on the emulator using Android 4.0.3, but fails with a "Bad request" HTTP 400 Error on Android 2.3.5 (both emulator and real device). I do not have control over the server, so I cannot see what the

Inconsistent HttpUrlConnection behaviours on Android - how to debug?

南笙酒味 提交于 2020-01-14 10:22:31
问题 I have a weird problem: Implementing an interface to a webserver in my Android App, I connect to it using a HttpsUrlConnection. The connection uses additional HTTP Basic authorization (using setRequestProperty ), but otherwise is a plain GET request over HTTPS. It works perfectly fine using it on the emulator using Android 4.0.3, but fails with a "Bad request" HTTP 400 Error on Android 2.3.5 (both emulator and real device). I do not have control over the server, so I cannot see what the

HttpURLConnection.getResponseCode() throws IOException when code is known

萝らか妹 提交于 2020-01-11 04:30:07
问题 How come HttpURLConnection.getResponseCode() throws IOException even if the status is known? Caused by: java.io.IOException: Server returned HTTP response code: 412 for URL: <my url> It's not a problem of getting the response code because it is written in the exception message. I would expect to have an option to get the status code (even if it's not ~200) without getting an exception, so I'll be able to decide in my code what to do. Full stack trace: Caused by: java.io.IOException: Server

java.io.IOException: unexpected end of stream on Connection in android

我与影子孤独终老i 提交于 2020-01-09 03:39:04
问题 I have web service URL, it working fine. It gives the JSON data. When I use HttpURLConnection , InputStream , I am getting an error. like java.io.IOException: unexpected end of stream on Connection{comenius-api.sabacloud.com:443, proxy=DIRECT hostAddress=12.130.57.1 cipherSuite=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 protocol=http/1.1} (recycle count=0) try{ URL url = new URL("https://comenius-api.sabacloud.com/v1/people/username="+username+":(internalWorkHistory)?type=internal&SabaCertificate=

https post in android 4.0

江枫思渺然 提交于 2020-01-07 07:14:30
问题 I am testing a https post on android , I have 2 android devices, this code perfectly worked on my 2.3 device but will be blocked in my 4.1 device at "retcode=urlCon.getResponseCode();", also I have checked the packet in sniffer the post request has been sent and the server did reply the https response,but it still be blocked until timeout. private String GetHttpPage(HttpsURLConnection urlsCon,String host,String url,String reference,boolean type,String curcookie,String postparam){ String query

https post in android 4.0

三世轮回 提交于 2020-01-07 07:14:05
问题 I am testing a https post on android , I have 2 android devices, this code perfectly worked on my 2.3 device but will be blocked in my 4.1 device at "retcode=urlCon.getResponseCode();", also I have checked the packet in sniffer the post request has been sent and the server did reply the https response,but it still be blocked until timeout. private String GetHttpPage(HttpsURLConnection urlsCon,String host,String url,String reference,boolean type,String curcookie,String postparam){ String query

Capturing Android applicataion traffic using FIddler

僤鯓⒐⒋嵵緔 提交于 2020-01-06 16:18:24
问题 So far I managed to capture the traffic of local Java programs & Android browser successfully. However, I failed to capture traffic of my Android application (using HttpsUrlConnection ). While following the steps in this guide to configure the WiFi network on the device, in the step of downloading the certificate I faced an odd behavior as Chrome raised an error and Firefox installed it without opening the expected dialog: But when I try to download it again, it says that the certificate is

How to avoid EOFException for an empty HTTP response from HttpURLConnection?

不想你离开。 提交于 2020-01-06 15:41:31
问题 I'm sending an HTTP request to a server which legitimately returns a blank response with HTTP response code = 200 (OK). But this causes the marked line below to throw an EOFException : InputStream responseStream = httpURLConnection.getInputStream(); final String contentEncoding = this.connection.getContentEncoding(); if ("gzip".equalsIgnoreCase(contentEncoding)) { responseStream = new GZIPInputStream(responseStream); // throws EOFException } There may be an obvious way to prevent this but I