This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Sockets and Internet Protocols and the fly likes java.net.SocketException (while getting data from an url) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "java.net.SocketException (while getting data from an url)" Watch "java.net.SocketException (while getting data from an url)" New topic
Author

java.net.SocketException (while getting data from an url)

subodh varshney
Greenhorn

Joined: Aug 01, 2005
Posts: 11
Hi All,
i m using following code for url connection, and getting error.
Please help me.

URL url = new URL(urlString);
HttpsURLConnection conn=(HttpsURLConnection)url.openConnection();
conn.setHostnameVerifier(new MyHostnameVerifier());
conn.setAllowUserInteraction(true);
conn.setDoOutput(false);
conn.setRequestMethod("GET");
conn.getContent();
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String str="";
String str1="";
while ((str = in.readLine()) != null) {
if(!str.equalsIgnoreCase(""))
System.out.println("STR:::::"+str);
str1+=str+"\n";
}
in.close();

<-------------------I am getting following error ---------------->

java.net.SocketException: Unexpected end of file from server
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:802)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:702)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:583)
at java.net.URLConnection.getContent(URLConnection.java:582)Unable to send the message
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: java.net.SocketException (while getting data from an url)
 
jQuery in Action, 3rd edition