Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Writing a HTTPClient

Posted on 2000-03-13
5
Medium Priority
?
197 Views
Last Modified: 2008-03-17
Hello ,

I try to write a bot which fetches a Website by a given URL using the URL and HTTPCon. classes.
My Problem is, i am using s.th. like << while ( (byteArr = f.read()) != null) >> to check if the read packet is null or not for the while loop condition.
But with this approach I dont get the full file cause sometimes the connection is stalled and I only get half of the site. Is there a possibility which is compactible with HTTP 1.0 and 1.1 to check wether the file is full read or not

Thanx a lot for any advices and hints ...

Binh  
0
Comment
Question by:kaber
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 

Expert Comment

by:kbeier
ID: 2614465
Hi kaber,

What about using a BufferedReader:

BufferedReader in = new BufferedReader(new InputStreamReader(MyHTTPUrlConnection.getInputStream()));

and then using:
String inputLine;
while ((inputLine = in.readLine())
{
    //do your stuff here
}

Just a suggestion.  Hope it helps.

:-)
0
 
LVL 4

Expert Comment

by:jerch
ID: 2614483
Yes, you can use the content-length header (use getContentLength() of HttpURLConnection).  But the problem not all web sites provide this information.  If the content-length is available, you can compare the size of the actual file to the content-length header.  So you would be able to determine if you were able to download the complete file.

Hope this helped...

Jerson
0
 

Expert Comment

by:zevious
ID: 2614851
Use Socket.setSoTimeout();

This might solve it...
0
 

Author Comment

by:kaber
ID: 2615639
Hi ,

kbeier your comment helps me out to solve the prob. Thanx a lot , I would give you the points, but how can I do that ?
0
 

Accepted Solution

by:
kbeier earned 300 total points
ID: 2616012
Hi kaber,

I will post my comment as an answer for you (hopefully this will let you allocate the points ;-)).  My comment was:

What about using a BufferedReader:

BufferedReader in = new BufferedReader(new InputStreamReader(MyHTTPUrlConnection.getInputStream()));

and then using:
String inputLine;
while ((inputLine = in.readLine())
{
    //do your stuff here
}

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn different types of Android Layout and some basics of an Android App.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question