B
BADBOY
Hi,
I am trying to get an application to post to a servlet, but keep getting
a http 401 code(invalid username or password).
Am almost certain ive got the server, username and password set up right.
Can anyone see anything wrong with code
private void doLogin(String name,String pass){
try{
URL url = new URL("http://127.0.0.1/servlet/jl.CheckLogin");
String
request="name="+URLEncoder.encode(name,"UTF-8")+"&pass="+URLEncoder.encode(p
ass,"UTF-8")+"\r\n";
URLConnection c = url.openConnection();
c.setDoOutput(true);
c.setDoInput(true);
c.setUseCaches(false);
c.setRequestProperty("Authorization:","Basic
"+authName+":"+authPass);
c.setRequestProperty("Content-type","application/x-www-form-urlencoded");
c.setRequestProperty("Content-Length",""+request.length());
DataOutputStream out = new
DataOutputStream(c.getOutputStream());
out.writeBytes(request);
out.flush();
out.close();
// DataInputStream in =new DataInputStream(c.getInputStream());
// Handle data from servlet through in.
}catch(MalformedURLException murle){
statusLabel.setText(String.valueOf(murle));}
catch(IOException ioe){ statusLabel.setText(String.valueOf(ioe));}
}
I am trying to get an application to post to a servlet, but keep getting
a http 401 code(invalid username or password).
Am almost certain ive got the server, username and password set up right.
Can anyone see anything wrong with code
private void doLogin(String name,String pass){
try{
URL url = new URL("http://127.0.0.1/servlet/jl.CheckLogin");
String
request="name="+URLEncoder.encode(name,"UTF-8")+"&pass="+URLEncoder.encode(p
ass,"UTF-8")+"\r\n";
URLConnection c = url.openConnection();
c.setDoOutput(true);
c.setDoInput(true);
c.setUseCaches(false);
c.setRequestProperty("Authorization:","Basic
"+authName+":"+authPass);
c.setRequestProperty("Content-type","application/x-www-form-urlencoded");
c.setRequestProperty("Content-Length",""+request.length());
DataOutputStream out = new
DataOutputStream(c.getOutputStream());
out.writeBytes(request);
out.flush();
out.close();
// DataInputStream in =new DataInputStream(c.getInputStream());
// Handle data from servlet through in.
}catch(MalformedURLException murle){
statusLabel.setText(String.valueOf(murle));}
catch(IOException ioe){ statusLabel.setText(String.valueOf(ioe));}
}