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
1 answer

Android: how to limit download speed

I use AndroidHttpClient to download videos from internet. There are ways to increase download speed, but I want to know how to slow down the download speed using AndroidHttpClient or HttpURLConnection ? Is there any interfaces or configuration for…
mianlaoshu
  • 2,342
  • 3
  • 27
  • 48
1
vote
1 answer

Issues with Mocking HttpURLConnection using Mockito

I am trying to mock a HttpURLConnection object but I cant seem to get it right. Here is the method I would like to test. @Override public JSON connect() throws IOException { HttpURLConnection httpConnection; String finalUrl = url; URL…
BudsNanKis
  • 224
  • 5
  • 17
1
vote
1 answer

More threads = Less requests per second?

I'm currently writing a crawler in java, and I'm stuck by something. In my crawler, I have threads downloading a static distant page, using HttpURLConnection. I tried to download one small file (2kb) with different parameters. The connection has a…
Nisalon
  • 235
  • 2
  • 10
1
vote
0 answers

Java, HttpURLConnection not reading polish letters

I want to get content from website where are used polish letter (eg. ś, ć, ę etc) by opening connection using HttpURLConnection. I set InputStreamReader to UTF-8, but that didn't help. This is my class responsibled for connection: import…
Sylwek
  • 856
  • 1
  • 9
  • 24
1
vote
1 answer

How to connect to Cisco Show and Share API from Java app

I can connect to the API via Firefox's RESTClient, but not through my java app. HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type",…
Joe Essey
  • 3,457
  • 8
  • 40
  • 69
1
vote
1 answer

RSS Reader 403 and 503 Errors

I am trying to read the RSS Feed of http://www.youm7.com/new3agelrss.asp using RSS feeds with Java - Tutorial for Lars Vogel. I managed to read another rss feeds using the exact code without problems. For this link I get Server returned HTTP…
hasan
  • 23,815
  • 10
  • 63
  • 101
1
vote
1 answer

HttpURLConnection returns -1 as a response code

I'm trying to fetch data from an API via HttpURLConnection but getting IOException with a message: Invalid Http response However, when I paste the request url to the browser I'm getting the correct response with 200 as a response code. Here's…
J.Koskela
  • 421
  • 1
  • 6
  • 19
1
vote
2 answers

Server exceptions while doing many (sequential) HTTP POST commands from Java to a PHP file

A series of sixty HTTP POST's to a PHP file located on my Godaddy server repeatedly cause a SocketException (when using Java JRE6/JRE7), NoHttpResponseException (in Android) or occasionally a SocketTimeoutException (both Java & Android) on the 61st…
SuperDave
  • 41
  • 1
  • 3
1
vote
1 answer

application crashes if the server is closed due to timeout. How can I catch it?

String urlStr = "nana.com/nana/api/v1" HttpURLConnection conn = null; BufferedReader rd = null; StringBuilder sb = null; try { URL url = new URL(urlStr); conn = (HttpURLConnection)…
user2775286
1
vote
1 answer

Android make DELETE web service call

I am playing with instagram api endpoints. Their call sample is: curl -X DELETE https://api.instagram.com/v1/media/{media-id}/likes?access_token=ACCESS-TOKEN I am trying to make the call from my android app like this: URL url = new…
Alin
  • 14,809
  • 40
  • 129
  • 218
1
vote
1 answer

HttpURLConnection GET download file, doesn't return anything.

I am using HttpURLConnection to download a xml file. I can see the file in my web browser, it takes over 10 seconds to load. But i can see the content eventually. But I am not able to download it through my java code. It seems like all my…
topcan5
  • 1,511
  • 8
  • 30
  • 54
1
vote
1 answer

how to use KeepAliveCache get(url,object)

I have an old application that seems to be written in java 1.4 or 1.3. and i am migrating ir to 1.7. The issue is that it is using HttpURLConnection kac.get(URL) while the new signature is kac.get(URL,Object). Can someone explain me how to use this…
user1249212
  • 333
  • 2
  • 5
  • 12
1
vote
1 answer

How do I upload both form data and multiple files from my android app, using HTTPURLConnection to my server, where I am using PHP?

I have an android application that is sending 1 or more zip files to the server. I'd like to send some additional form data along with the files, because the form data will be used to determine the disposition of the files. I've been able to upload…
Rben
  • 489
  • 1
  • 7
  • 18
1
vote
2 answers

How to save the file from HTTPS url in JAVA?

I am trying to save a file from URL using outputstream. The URL is secure by https. So I got some error when I try to get the file as the following javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building…
Takumi
  • 355
  • 1
  • 7
  • 19
1
vote
3 answers

Java HttpURLConnection post method not working

I am using HttpURLConnection to send data to a server via POST. I set the headers then get the output stream and write some bytes then close the output stream. I am trying to get the next page for schedule details from given url. But some how i am…
user2589193
  • 69
  • 1
  • 6
  • 13
1 2 3
99
100