Questions tagged [urlconnection]

URLConnection is a class that enables Java code to access data available from various urls.

674 questions
16
votes
6 answers

Instantiate Java Abstract class?

Relatively new Java programmer and I've been taught that you can't create an instance of an abstract class. I've also done a little research and I learned that in most cases when it appears an abstract class is being created, it is actually an…
Ausome
  • 203
  • 1
  • 6
15
votes
2 answers

How to send a cookie in a URLConnection?

What is the proper way to send a 'full' cookie across a URLConnection? I've been using: URL url = new URL(page); URLConnection urlConn = url.openConnection(); urlConn.setRequestProperty("Cookie", myCookie); urlConn.setUseCaches(true);…
E Paiz
  • 661
  • 4
  • 9
  • 19
14
votes
4 answers

how to remove a header from URLConnection

I am talking to a file upload service that accepts post data, not form data. By default, java's HttpURLConnection sets the Content-Type header to application/x-www-form-urlencoded. this is obviously wrong if i'm posting pure data. I (the client)…
Jeffrey Blattman
  • 22,176
  • 9
  • 79
  • 134
13
votes
2 answers

In java, how to create HttpsURLConnection or HttpURLConnection based on the url?

I'm working on a project where I'm creating a class to run http client requests (my class acts as a client). It takes in a url and a request method (GET, POST, PUT, etc) and I want to be able to parse the URL and open a HttpsURLConnection or…
Adam Plumb
  • 3,738
  • 8
  • 35
  • 34
13
votes
5 answers

Do Applets use Browser for HTTP Requests?

Is there any interaction between applets and their hosting browser when making HTTP requests, or are requests made completely independently of native browser code? Specifically, do Java applets running in a browser have some implicit way of sharing…
DeejUK
  • 12,891
  • 19
  • 89
  • 169
12
votes
2 answers

Setting custom header using HttpURLConnection

I am simply making a GET request to a Rest API using HttpURLConnection. I need to add some custom headers but I am getting null while trying to retrieve their values. Code: URL url; try { url = new URL("http://www.example.com/rest/"); …
Abhishekh Gupta
  • 6,206
  • 4
  • 18
  • 46
12
votes
2 answers

can't get response header location using Java's URLConnection

can someone kindly suggest what I'm doing wrong here? I'm trying to get the header location for a certain URL using Java here is my code: URLConnection conn = url.openConnection(); String location = conn.getHeaderField("Location"); it's strange…
Yaniv Golan
  • 982
  • 5
  • 15
  • 28
11
votes
4 answers

How can I specify the local address on a java.net.URLConnection?

My Tomcat instance is listening to multiple IP addresses, but I want to control which source IP address is used when opening a URLConnection. How can I specify this?
stian
  • 2,874
  • 3
  • 24
  • 38
11
votes
3 answers

asynchronous HTTP request in java

How to send asynchronous HTTP GET/POST request in java without waiting/reading response ?I don't want to use any third party libraries ..
pavan
  • 3,225
  • 3
  • 25
  • 29
11
votes
5 answers

Java URLConnection error with ntlm authentication, but only on Linux and only Java 7

I am trying to open an http connection to an url protected with the NTLM authentication scheme. This code has been working correctly for 2 year when we were on Java 6.I wrote a small java program which access that particular url to make the test…
Yanick
  • 151
  • 1
  • 1
  • 8
11
votes
2 answers

Android - Default user agent for URLConnection?

I am creating a regular HTTP connection using this code: URLConnection cn = new URL( "http://...." ).openConnection(); cn.connect(); How do I find out the default user agent for my HTTP connection? I tried using the following codes but they all…
Enzo Tran
  • 5,750
  • 6
  • 31
  • 36
11
votes
5 answers

Reading a web page in Java IOException Premature EOF

I am frequently getting a 'Premature EOF' Exception when reading a web page. The following is the StackTrace java.io.IOException: Premature EOF at sun.net.www.http.ChunkedInputStream.readAheadBlocking(ChunkedInputStream.java:556) at…
Ranjith
  • 1,623
  • 3
  • 21
  • 34
10
votes
2 answers

Got stuck at java.net.SocketInputStream.socketRead0(Native Method)

I got a stuck thread at java.net.SocketInputStream.socketRead0(Native Method). Please see the thread dump below. It's been in this status for 3 hours. Thread-0" prio=10 tid=0x00007facd02a5000 nid=0x309 runnable…
BurningDocker
  • 133
  • 1
  • 8
10
votes
2 answers

Java HTTPUrlConnection timeout does not work

I've written a programm that opens a httpurlconnection to a website through random proxies. My httpurlconnection is called conn. Now I know, that some of those proxies might be too slow, so i've set the timeout of the connection to 40000…
user1927372
  • 101
  • 1
  • 4
9
votes
2 answers

Java HttpURLConnection: Content Length computation

I'm currently developing a library for the bitbucket issues RESTful API. I made good progress and now I'm going to tackle the section Updating an Issue which demands an HTTP PUT Request. Now I'm stuck because of the HTTP Error Code 411 Length…
f4lco
  • 3,728
  • 5
  • 28
  • 53
1 2
3
44 45