Questions tagged [urlconnection]

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

674 questions
6
votes
1 answer

Proxy With Java URLConnection class

I am very new with Java. I am using following code for the calling REST API, its working fine in simple environment but when I used with proxy environment Its throwing the NullPointerException. I found result on google that we have to set proxy…
Govind Malviya
  • 13,627
  • 17
  • 68
  • 94
6
votes
3 answers

Is it possible to check progress of URLconnection.getInputStream()?

I want to check progress of downloading file by URLconnection. Is it possible or should I use another library? This is my urlconnection function: public static String sendPostRequest(String httpURL, String data) throws UnsupportedEncodingException,…
latata
  • 1,703
  • 5
  • 27
  • 57
6
votes
1 answer

java.net.URLConnection.guessContentTypeFromStream and text/plain

All, I am trying to identify plain text files with Mac line endings and, inside an InputStream, silently convert them to Windows or Linux line endings (the important part is the LF character, really). Specifically, I'm working with several APIs that…
Adam Norberg
  • 3,028
  • 17
  • 22
6
votes
2 answers

HttpURLConnection.getInputStream() throws SocketTimeoutException

I am using HttpURLConnection to upload an image and get its response. It works on emulator and my XiaoMi device. However, it always get a SocketTimeoutException on my Sony device on the line connection.getInputStream(). I've tried to set timeouts to…
6
votes
1 answer

Jax-ws set connection timeout for reading wsdl and sending request

Our application need to send some request to SOAP service. We use wsimport command to generate class for our client. But sometime when service down or some network problem, our request hang until timeout and that is rather too long. We want to…
mameo
  • 639
  • 8
  • 25
6
votes
1 answer

301/302 Redirect not working in Android (work differently in different versions)

When using a URLConnection, the 301 redirect doesn't work, doesn't even show a Location header, using getHeaderFields(). It is a blank list, except in newer Android (I tested 4.1 and it worked). It looks like something this has been reported in the…
NoBugs
  • 9,310
  • 13
  • 80
  • 146
6
votes
2 answers

java.net.ConnectException: Connection timed out while connecting through a proxy

I am trying to download a zip file from a URL and store it in the local system using java code. I am also using system proxy for the same. Its unable to connect to the url. Any idea? public static void main() { try { long startTime =…
Chirag
  • 341
  • 2
  • 7
  • 14
6
votes
4 answers

Expanding a shortened url to its original full length url in java

I'm attempting to take a shortened url and expand it out to its original full length url in a string format in java. I've been able to track down a tutorial online, however I'm unable to get this to actually get me the full url. Has anyone done this…
Edmund Rojas
  • 6,376
  • 16
  • 61
  • 92
5
votes
3 answers

URLConnection does not handle content length via proxy correctly

I faced the following problem: When URLConnection is used via proxy the content length is always set to -1. First I checked that proxy really returns the Content-Length (lynx and wget are also working via proxy; there is no other way to go to…
dma_k
  • 10,431
  • 16
  • 76
  • 128
5
votes
1 answer

Strict and reliable timeout on HttpClient

I'm reading a web page using HttpClient like this: httpclient = new DefaultHttpClient(); httpget = new HttpGet("http://google.com"); HttpResponse response = httpclient.execute(httpget); HttpEntity entity =…
Ariyan
  • 14,760
  • 31
  • 112
  • 175
5
votes
2 answers

How to send an HTTP header in java

Is it possible to send a Http header via a URL connection in java? I had this working using sockets, but ran into issues with a firewall which don't seem to be a problem with URLConnection. From looking at the API I get the impression that the…
Simonw
  • 852
  • 4
  • 12
  • 29
5
votes
3 answers

Calling a Servlet from a Java application

I want to call a Servlet from a Java application. The problem is, that the call seems not to reach the Servlet. I do not get any error, but do not reach the first output "doPost" in the Servlet. If I open the URL in a web browser, I got - of course…
IceJava
  • 53
  • 1
  • 1
  • 3
5
votes
1 answer

java.lang.NegativeArraySizeException when using URLConnection

I'm trying to create a Telegram bot and my code already works, but suddenly I can't start my program, as it crashes with the following error. I did not change any code or do anything. Perhaps this is a bug of the operating system? Exception in…
fergusq
  • 179
  • 1
  • 9
5
votes
3 answers

Is it really necessary to use url.openConnection()?

As we all know both these codes will yield the same result public class MainApp { public static void main(String[] args) throws IOException { URL google = new URL("http://www.google.com"); google.openConnection(); …
user6538026
5
votes
0 answers

UrlConnection : SSLProtocolException: SSL handshake aborted: ssl=0x631b60c8: Failure in SSL library, usually a protocol error

I am currently working on the migration of an Android from HttpClient to UrlConnection. I am facing some issue on, at least, Android 4.2.2. The URL I am trying to call to is an https URL and I have to use a client certificate. Based on this blog…
rolandl
  • 1,769
  • 1
  • 25
  • 48