httpurlconnection

HTTPUrlConnection error (Can't open OutputStream after reading from an inputStream)

倾然丶 夕夏残阳落幕 提交于 2019-12-07 13:38:32
问题 I am new to Java and am running into the above mentioned error while using HTTPURLConnection to send multiple post requests on Android. I have written an HTTPTransport class in which I would like to have sendMessage and recvMessage methods. public class HTTPTransport { private HttpURLConnection connection; public HTTPTransport() { URL url = new URL("http://test.com"); connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); connection.setDoInput(true);

Send UTF-8 chars via HttpURLConnection failing

风格不统一 提交于 2019-12-07 11:36:20
问题 I have spent half Sunday on this now I need help: I want to send a String including special chars UTF-8 encoded to a server using Java HttpURLConnection. The correct encoding of the chars fails. Example: strToSend: ä ù € strUrlEncoded: %C3%A4+%C3%B9+%E2%82%AC strReceived:ä ù ⬠My code: urlConnection = (HttpURLConnection) new URL("http://localhost:8080/NetworkingServer/ServerServlet").openConnection(); urlConnection.setUseCaches(false); urlConnection.setDoOutput(true); // Triggers POST.

NLTM auth using HttpUrlConnection failing

只愿长相守 提交于 2019-12-07 08:01:12
问题 I am trying to authenticate against a server supporting NTLM authentication in my Java application using java.net's HttpUrlConnection. The problem is that the application fails to send the Authenticate response. I have attached proxy to the http connection so that the traffic is routed via fiddler. In fiddler i can see Negotiate message being sent, and server Challenge is received. But after this, the application just stops saying it got a 401, without sending the type3 authenticate message.

How to switch from HttpURLConnection to HttpClient

。_饼干妹妹 提交于 2019-12-07 07:56:37
问题 this is my first question, so please, bear with me. I have a Swing application, which gets data in a for of XML from a server through HttpURLConnection. Now I'm trying to create a constant request-respond connection with the server, to check if there are any updates for the application (as the checking has to be done regularly and often (every second or so)). In some question's comment I read that it would be better to use Apache HttpClient instead of HttpURLConnection to maintain a live

HTTP 403 while executing a PUT request

孤者浪人 提交于 2019-12-07 07:13:24
I am creating a django rest api, and I'm trying to send JSON data via PUT request from an Android device, using HttpUrlConnection. URL url = new URL(myurl); conn = (HttpURLConnection) url.openConnection(); conn.setReadTimeout(10000 /* milliseconds */); conn.setConnectTimeout(15000 /* milliseconds */); conn.setRequestMethod("PUT"); conn.setDoInput(true); conn.setDoOutput(true); conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); conn.setRequestProperty("Accept", "application/json"); Log.v("Apiput", MainActivity.cookieManager.getCookieStore().getCookies().get(0).toString(

How to disconnect an HttpUrlConnection on HTC (Froyo and below) phones?

一个人想着一个人 提交于 2019-12-07 05:28:20
问题 I need to disconnect a long polling http request from the client side in some cases. The relevant part of the HttpUrlConnection I make to the server is as follows (all the code below is within a Thread's run() method): try { URL url = new URL(requestURL); connection = (HttpURLConnection) url.openConnection(); connection.setRequestProperty("Accept-Charset", "UTF-8"); connection.setConnectTimeout(5 * 1000); connection.setReadTimeout(60 * 1000); connection.setRequestMethod("GET"); // read the

Why does HttpURLConnection.getResponseCode() throws IOException? [duplicate]

强颜欢笑 提交于 2019-12-07 04:08:23
问题 This question already has answers here : HttpURLConnection.getResponseCode() throws IOException when code is known (2 answers) Closed 3 years ago . I can see that getResponseCode() method is just a getter Method that returns the statusCode already set by the a connect action that happened before. So in this context why does it throw an IOException ? Am i missing something? 回答1: From javadoc: It will return 200 and 401 respectively. Returns -1 if no code can be discerned from the response (i.e

Android Http url connection Throwing File Not Found Exception at getInputstream

时间秒杀一切 提交于 2019-12-07 03:54:12
问题 I am trying to post some json string to a rest sever but I'm getting a java file not found exception at get input stream. Here is my code: package com.muzima.view.sample.activities; import javax.servlet.http.HttpServletResponse; import com.muzima.view.sample.R; import android.app.Activity; import android.content.Intent; import android.os.AsyncTask; import android.os.Bundle; import android.util.Base64; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener

java httpurlconnection cutting off html

余生颓废 提交于 2019-12-07 03:05:40
问题 Hey, I'm trying to get the html from a twitter profile page, but httpurlconnection is only returning a small snippet of the html. My code for(int i = 0; i < urls.size(); i++) { URL url = new URL(urls.get(i)); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestProperty("User-Agent","Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6"); System.out.println(connection.getResponseCode()); String line; StringBuilder

Java : HTTP(S)/WebServices connections through NTLM proxy

孤街浪徒 提交于 2019-12-07 03:04:12
问题 We have a java client side application deployed in our customer (a java application, not an applet). This application checks connectivity with an url.openConnection() and calls web services (with CXF/JAX-WS) through internet. Some of our customer network use proxies to access to the external world. The client side application sets the proxy parameter in java system properties : System.setProperty("proxySet", "true"); //Obsolete ? System.setProperty("http.keepAlive", "false"); System