Questions tagged [httpurlconnection]

HttpURLConnection instance is used to make a single request but the underlying network connection to the HTTP server may be transparently shared by other instances.

The HttpURLConnection class is used to send and receive data over the web using the HTTP protocol. Data may be of any type and length.

Uses of this class follow a pattern:

  • Obtain a new HttpURLConnection by calling URL.openConnection() and casting the result to HttpURLConnection.
  • Prepare the request. The primary property of a request is its URI. Request headers may also include metadata such as credentials, preferred content types and session cookies.
  • Optionally upload a request body. Instances must be configured with setDoOutput(true) if they include a request body. Transmit data by writing to the stream returned by getOutputStream().
  • Read the response. Response headers typically include metadata such as the response body's content type and length, modified dates and session cookies. The response body may be read from the stream returned by getInputStream(). If the response has no body, that method returns an empty stream.
  • Disconnect. Once the response body has been read, the HttpURLConnection should be closed by calling disconnect(). Disconnecting releases the resources held by a connection so they may be closed or reused.

For more information visit HttpURLConnection.

3261 questions
1
vote
0 answers

restfb falls back on previous proxy if new proxy fails

I am trying to get proxy changes to work with restfb. I am changing proxy details in a running JVM. Scenarios covered: No proxy at first, fails as expected, configured proxy, works as expected. Configured correct proxy, works as expected, changed…
Chiranjib
  • 1,763
  • 2
  • 17
  • 29
1
vote
2 answers

Retrieve redirected URL with Java / HttpURLConnection

Given a URL (String ref), I am attempting to retrieve the redirected URL as follows: HttpURLConnection con = (HttpURLConnection)new URL(ref).openConnection(); con.setInstanceFollowRedirects(false); …
barak manos
  • 29,648
  • 10
  • 62
  • 114
1
vote
3 answers

Java HttpURLConnection | POST method | Sequence of HTTP header fields

I am trying to "spoof" a Firefox HTTP POST request in Java using java.net.HttpURLConnection. I use Wireshark to check the HTTP headers being sent, so I have (hopefully) reliable source of information, why the Java result doesn't match the ideal…
Kovács Imre
  • 715
  • 2
  • 7
  • 17
1
vote
1 answer

HttpURLConnection disconnect doesn't work in Android

The method disconnect from HttpURLConnection seems not to work properly. If I execute the following code: url = new URL("http:// ..."); connection = (HttpURLConnection) url.openConnection…
Arutha
  • 26,088
  • 26
  • 67
  • 80
1
vote
2 answers

Why doesn't HttpClient work but HttpUrlConnenction do when posting data to form

I'm building an android app which should perform a GET on my site to get two cookies and then perform a post to the same site with these cookies. As mentioned I start of with the GET and I'm using org.apache.http.client.HttpClient to perform this…
jakob
  • 5,979
  • 7
  • 64
  • 103
1
vote
1 answer

sending data to server with httpUrlConnection

I am trying to create a Simplest WebServer and Client using HTTP. I should use a tunnel way that uses two connections at the same time; one is a GET connection to recieve data and the other is a POST connection to send data back. Below is my…
Sidaoui Majdi
  • 399
  • 7
  • 26
1
vote
1 answer

HttpURLConnection and no internet

Don't know if I'm the first one to run into this, but I'll post it here to save someones time. Ok, so after playing around and trying out HttpURLConnection to do some HTTP requests from Android I wondered what would happen if I used it with Internet…
VM4
  • 6,321
  • 5
  • 37
  • 51
1
vote
0 answers

REST request on Android

I'm writing my first Android app where the first thing to do is collect a list of maps from a server, but I'm having difficulty getting a simple REST request working. I've been following a number of tutorials and am trying to employ both AsyncTask…
Benjin
  • 2,264
  • 2
  • 25
  • 50
1
vote
0 answers

JavaFX URLConnection HTTP Response Codes

I am struggling bad time trying to make an AngularJS application to run properly into an embedded JavaFX Webkit browser. During the initialization, this is pretty normal that the application server returns a HTTP 401 (unauthorized). The Ajax handler…
Luciano Greiner
  • 183
  • 2
  • 13
1
vote
1 answer

Java puts the xml attributes in "request version" part of HTTP request

I am able to send the following request using browser and receive the correct response, but when I send it using following code the server return an error. I suspect the problem is that Java puts the xml attributes in "request version" part of HTTP…
user1386522
1
vote
0 answers

How much bandwidth has been used in my app

I'm developing android app. I call HttpURLConnection connection = (HttpURLConnection) fileURLInfo.openConnection(); to get file download information(file name, file size, format, ...) if everything is OK call InputStream input = new…
Du Huynh
  • 151
  • 1
  • 13
1
vote
2 answers

Right way to manage HTTP connection in Android

I have written two programs which handle the HTTP request. I wanted to know if one is better than other - Program 1 (Using HttpURLConnection) URL url = new URL("https://www.google.com/"); HttpURLConnection connection =…
Fox
  • 9,384
  • 13
  • 42
  • 63
1
vote
1 answer

HTTURLConnection setFixedLengthStreamingMode leads to SSL broken pipe exception

I am trying to upload a file to a REST API from Egnyte If I don't use setFixedLengthStreamingMode(...) the file is uploaded without getting exceptions, when I use setFixedLengthStreamingMode(...) I get once in while a IO/SSL Exception -> Broken…
David
  • 3,971
  • 1
  • 26
  • 65
1
vote
0 answers

Post requests received as GET with android HttpURLConnection

I am trying to upload a binary file (a serialized object) to my Google app engine server, but I only receive GET requests. Here's my code: private void sendPostRequest() { if (!isConnected()) { return; } File file = new…
Yotam
  • 9,789
  • 13
  • 47
  • 68
1
vote
1 answer

HttpURLConnection getInputStream() has one second delay

I am using HttpURLConnection for making POST requests. I observe always the same behaviour during tests: first request runs very fast (miliseconds) all following requests take one second + some miliseconds So something is causing 1 second delay.…
Tomasz
  • 988
  • 1
  • 9
  • 23