[Add] I forgot to mark this as question [Add]
I wrote a smalll program that send the xml to soap webservice on the server
If I use the browser to type the link on(http://myserver/myservices/RequestWS) , it pops up a window authenfication box. I type user name and password in and it works (logged in, see the message from the server)
However, if I run the java code below, the error is thorwn when I write to the outputStream.
public static void main(String[] args) throws Exception {
String SOAPUrl = args[0];
String xml = args[1];
URL url = new URL(SOAPUrl);
URLConnection connection = url.openConnection();
HttpURLConnection httpConn = (HttpURLConnection) connection;
byte[] b = xml.getBytes();
// Set the appropriate HTTP parameters.
httpConn.setRequestProperty( "Content-Length",String.valueOf( b.length ) );
httpConn.setRequestProperty("Content-Type","text/xml; charset=utf-8");
httpConn.setRequestMethod( "POST" );
httpConn.setDoOutput(true);
httpConn.setDoInput(true);
httpConn.setAllowUserInteraction(true);
httpConn.setDefaultUseCaches(false);
httpConn.setUseCaches(false);
OutputStream out = httpConn.getOutputStream();
System.out.println("httpConn.getResponseCode():"+httpConn.getResponseCode());
out.write( b );
out.close();
}
The console is:
httpConn.getResponseCode():401
java.io.IOException: Server returned HTTP response code: 401 for URL: http://ADMIN:password@myserver/myservices/RequestWS
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.net.www.protocol.http.HttpURLConnection.getChainedException(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at SOAPClient.main(SOAPClient.java:81)
Caused by: java.io.IOException: Server returned HTTP response code: 401 for URL: http://ADMIN:password@myserver/myservices/RequestWS
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at java.net.HttpURLConnection.getResponseCode(Unknown Source)
at SOAPClient.main(SOAPClient.java:74)
Exception in thread "main"
Please help.
Thank you very much
Edited by: mycoffee on Jun 8, 2010 10:27 AM
Edited by: mycoffee on Jun 8, 2010 11:06 AM