rnicholus
asked on
Server returned HTTP response code: 400
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi rnicholus!
use URLEncoder.encode to encode a URL same as:
public static String forURL(String aURLFragment){
String result = null;
try {
result = URLEncoder.encode(aURLFrag ment, "UTF-8");
}
catch (UnsupportedEncodingExcept ion ex){
throw new RuntimeException("UTF-8 not supported", ex);
}
return result;
}
Phuoc
use URLEncoder.encode to encode a URL same as:
public static String forURL(String aURLFragment){
String result = null;
try {
result = URLEncoder.encode(aURLFrag
}
catch (UnsupportedEncodingExcept
throw new RuntimeException("UTF-8 not supported", ex);
}
return result;
}
Phuoc
ASKER
Dear moderator: I have provided the solution that I found for this problem in my post on 07/11/2006 05:40PM CDT.
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.
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.
ASKER
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
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
Awwwww, thanks. I feel bad now!
ASKER
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.