dcsimg
FileNotFoundException while posting http request from a client.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Mudit_Agarwal
Posted On:   Wednesday, August 1, 2001 06:07 PM

Hi! I am having problem while posting some contents to a servlet. If I put setRequestProperty for “Authorization” on HttpURLConnection then client doesn’t post the contents to the servlet & it give Error -- java.io.FileNotFoundException: http://ServerName/servlet/testSrv at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLCon nection.java:545) at testClient.main(testClient.java:77) If I don’t do setRequestProperty for “Authorization” on HttpURLConnection then client does post the contents to the servlet. Can someone tell me what I am missing? Partial code for client is given under. String login = "UserName   More>>

Hi!

I am having problem while posting some contents to a servlet. If I put setRequestProperty for “Authorization” on HttpURLConnection then client doesn’t post the contents to the servlet & it give Error --


java.io.FileNotFoundException: http://ServerName/servlet/testSrv
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLCon
nection.java:545)
at testClient.main(testClient.java:77)

If I don’t do setRequestProperty for “Authorization” on HttpURLConnection then client does post the contents to the servlet.


Can someone tell me what I am missing? Partial code for client is given under.



String login = "UserName:Password";

String encodedLogin = new BASE64Encoder().encodeBuffer(login.getBytes());

HttpURLConnection httpcon = (HttpURLConnection) new URL(url).openConnection();


httpcon.setRequestProperty("Authorization", "Basic " + encodedLogin);

httpcon.setRequestProperty("Content-Type","application/x-www-form-urlencoded");

httpcon.setDoOutput(true);

httpcon.setDoInput(true);

DataOutputStream os = new DataOutputStream(httpcon.getOutputStream());

os.writeBytes(data);

os.close();

BufferedReader is = new BufferedReader(new InputStreamReader(httpcon.getInputStream()));

// Read Buffer

is.close();

httpcon.disconnect();




Thanks in Advance --- Mudit

   <<Less

Re: FileNotFoundException while posting http request from a client.

Posted By:   Eugene_Kuleshov  
Posted On:   Sunday, August 5, 2001 03:32 PM

Why do you need to specify Content-Type in your client and setDoOutput( true)? GET method is default for openConnection and don't expect any output othet then headers...


I think that server decide that he can't return you url in requested encodind (which is "application/x-www-form-urlencoded"). Probably you have to specify "POST" method for your request.

About | Sitemap | Contact