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 doesnt 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 dont 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 doesnt 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 dont 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