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

Redirect using HTTPS connection Response

Created a new HTTPS connection and executed a GET method call on the connection URL. Instead of sending a 301 (30X) redirect I received a response with XHTML page data which inturn when handled in a browser will get submitted automatically and sent…
1
vote
0 answers

java get http response from target (302 - object moved) - hppt https protocols

I have the following situation that I'm still not able to manage: I wrote a java class to read a http response from a site that receive POST parameters I use HttpURLConnection and pass the input parameters the result obtained is another form that…
1
vote
1 answer

HttpURLConnection returns 422 code due to JSON

Without postParameters (JSON string, which is of course valid) everything works fine. But when I add postParameters 422 response appears. postParameters - {"password":"pass","email":"log"} - result of JSONObject.toString() URL urlToRequest = new…
eleven
  • 6,779
  • 2
  • 32
  • 52
1
vote
1 answer

Http certificate authentication with HttpUrlConnection from a WebLogic client app

I have a simple client application that downloads data from a site via HttpUrlConnection. The server uses cert auth. The app (outside of Weblogic) works proper. In standalone mode I set the cert via SSLSocketFactory. But the app have to work inside…
1
vote
2 answers

Why I get java.io.FileNotFoundException in getting the response to my httpUrlConnection?

I don't know if Im sending my file right to web api. Because nothing gives an error to client request code. But when I'm getting the response to the server it gives me a java.io.FileNotFoundException. So I think that there's wrong in my request code…
1
vote
0 answers

How to get content-length of file Im going to send?

I'm developing an application that can upload data to web server. But I don't know what I'm going to put on my content-length. I tried to get the size of my file and the other text-data that I'm going to upload but it's not correct. Can anyone know…
NewDroidDev
  • 1,656
  • 5
  • 19
  • 33
1
vote
2 answers

Check to see if a website is available

I am checking the network status of a device. using:- private boolean isNetworkAvailable() { ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo…
1
vote
4 answers

EOFException and FileNotFoundException in HttpURLConnection getInputStream()

When trying to connect to http://ws.audioscrobbler.com/2.0/ with post data using HttpURLConnection, I get (randomly) EOFException or FileNotFoundException: http://ws.audioscrobbler.com/2.0/ on my Nexus 4 running Android 4.2.2. Anybody can…
jul
  • 36,404
  • 64
  • 191
  • 318
1
vote
1 answer

Android Post UTF-8 HttpURLConnection

I am currently developing an application that needs to interact with the server but i'm having a problem with receiving the data via POST. I'm using Django and then what i'm receiving from the simple view is:
Ciro Costa
  • 2,455
  • 22
  • 25
1
vote
1 answer

Exception message not displayed

I have written an Android application in which I allow the user to select an image from the gallery and post it to an Internet server as a Base64 encoded String using HTTP REST-ful web-services upon click of a button. When the server is up/ running…
1
vote
1 answer

Android dont get the whole data

I am trying to download an XML file from a server and I use XMLpull parsher to handle it but It doesnt download the whole data everytime. Even if I Try To wait to download it (thread sleep). Do you have any idea why is this happen or how to solved…
meklod400
  • 129
  • 1
  • 2
  • 12
1
vote
2 answers

How do you get a return value from a php file called in Java

I'm using HttpURLConnection in Java (not Javascript) to call a PHP file which looks up a field in a mySQL database. In PHP how do I return the field contents (String) and in Java how do I receive them? Thank you. Awesome points to any who can help.…
bstrong
  • 680
  • 9
  • 20
1
vote
0 answers

wait for a long HTTP response in java

I hava a java application that calls a service. The service call will take about 5-10 minutes to complete its operation and return a status log as a response. (The reason behind the long duration is to copy files/images from one server to…
1
vote
2 answers

In Java, how do I set a progress bar for FileChannel?

For example, Channels.newChannel(url.openStream()); This one line opens the stream and gets data from it, but there is no way I can find the progress for it. Is there a way to do so?
user2519193
  • 211
  • 2
  • 14
1
vote
1 answer

HttpUrlConnection looking up DNS every time cause delay some time

I use HttpUrlConnection for http requesting in my app. Notice that it look up the dns in every request via Wireshark. The dns may delay some time, so the http request delays too. I don't think it need to look up the DNS every time, since the ip…
Lei Guo
  • 2,550
  • 1
  • 17
  • 22
1 2 3
99
100