Solved

Server returned HTTP response code: 400

Posted on 2006-07-11
8
1,046 Views
Last Modified: 2008-01-09
I'm trying to access a URL in my program. I opened the URL page in my web browser and it looks fine but when I run my program. I got an IOException that says: "Server returned HTTP response code: 400"

I'm not sure why I got this since it seems that I could open it in my web browser (Internet Explorer).

This is what I do in my code:
BufferedReader reader = new BufferedReader(new InputStreamReader(new URL("http://myPage.htm").openStream()));

Any advise?

Thanks
0
Comment
Question by:rnicholus
  • 3
  • 3
8 Comments
 
LVL 4

Accepted Solution

by:
astorer earned 200 total points
ID: 17086279
http://mypage.html is not a valid URL.  Are you opening a file on local disk or one from a web server?

Make sure that the URL in the IE navigation bar is copied exactly into your code.  I'd expect something like one of the following:

    file:///D:/directory/myPage.htm
    http://myhost/myPage.htm
    http://localhost/myPage.htm
0
 

Author Comment

by:rnicholus
ID: 17086333
Hi astorer,

Thanks for your reply. I used http://mypage.html just as an example.
I have found the solution that the URL actually have spaces which automatically converted to %20 by the browser but not by the java program.

I have requested this question to be removed.
0
 
LVL 6

Expert Comment

by:phuocnh
ID: 17086714
Hi rnicholus!
use URLEncoder.encode to encode a URL same as:
 public static String forURL(String aURLFragment){
    String result = null;
    try {
      result = URLEncoder.encode(aURLFragment, "UTF-8");
    }
    catch (UnsupportedEncodingException ex){
      throw new RuntimeException("UTF-8 not supported", ex);
    }
    return result;
  }
Phuoc
 
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:rnicholus
ID: 17095141
Dear moderator: I have provided the solution that I found for this problem in my post on 07/11/2006 05:40PM CDT.
0
 
LVL 4

Expert Comment

by:astorer
ID: 17097465
I'm not sure how the system works here.

People have been trying to help with solutions to the problem.  The reason that experts could not find the actual problems was that the question was not posed correctly.

Specifically,  the URL quoted was "http://myPage.htm".  This is clearly a bad URL and would have caused the problem defined.  In effect, I answered the question posed.  To refuse the points because the question was badly posed seems a little uncharitable and against the spirit of what Experts Exchange is all about.

0
 

Author Comment

by:rnicholus
ID: 17100787
Dear astorer:
I think you're right that I should have made the questions more clear at the very beginning, i.e: mentioning that the URL quoted was just an example.
I'm sorry.

Thanks for all the help
0
 
LVL 4

Expert Comment

by:astorer
ID: 17101767
Awwwww, thanks.  I feel bad now!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
bitbucket vs gitbucket 3 57
what is the main difference between git clone and fetch ann pull and push commands 2 72
javap not working 8 36
servlet example issue 6 31
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

910 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now