Hi Ryan,

Try setting the credentials using the following:

client.getState().setCredentials(null, sUrl, new UsernamePasswordCredentials(sServerAuthName, sServerAuthPassword));

Notice that null is not surrounded in quotes.

Mike

On Dec 13, 2004, at 6:45 AM, Ryan julius wrote:

Hello,

I have this String : sXmlMessage = "<mainMessage>messageBody</mainMessage>"
I would like to send sXmlMessage to a server named: webMServer whose address is http://pyasmp:5126.
webMServer use Basic authentication, the format of authentication(credentials!?!) is admin:servAdmin
credentials and sXmlMessage must be encoded using BASE64Encoder.
My question:
1.) How can I POST sXmlMessage to webMServer using HttpClient?


Note: I have unsuccessfully tried the BasicAuhentication example, I still have this message:

[WARN] HttpMethodBase - -No credentials available for the 'webMethods' authentication realm at pyasmp Method failed: HTTP/1.0 401 [ISS.0084.9004] Access Denied
2.) As U can see in the following piece of code, I have also tried HttpUrlConnection; but there is no link with the HttpClient. What might be wrong with this code?


Thanks.

The code:
=======
client.getState().setCredentials("null", sUrl, new UsernamePasswordCredentials(sServerAuthName, sServerAuthPassword));
HttpURLConnection httpUrlConnection = null;
try {
httpUrlConnection = (HttpURLConnection) url.openConnection();
} catch (IOException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
//Codage de la chaine de login et du fichier XML.
String authentication = (new sun.misc.BASE64Encoder()).encode( (sServerAuthName + ":"+ sServerAuthPassword).getBytes() );
httpUrlConnection.setRequestProperty("Authorization", "Basic "+ authentication );
String sXmlMessageCoded = "";
/*
try {
sXmlMessageCoded = URLEncoder.encode(sXmlMessage, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
*/
sXmlMessageCoded = URLEncoder.encode(sXmlMessage);


OutputStream out = null;
try {
out = httpUrlConnection.getOutputStream();
out.write(sXmlMessageCoded.getBytes());
} catch (IOException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
String sInLine = null;
String sInFullLine = null;
BufferedReader inReader;
try {
inReader =
new BufferedReader(
new InputStreamReader(httpUrlConnection.getInputStream()));
while ((sInLine = inReader.readLine()) != null) {
sInFullLine+=sInLine;
}
} catch (IOException e1) {
// TODO Bloc catch auto-g�n�r�
e1.printStackTrace();
}
System.out.println("R�sultat de la requ�te http : "+ new String(sInFullLine));


//************************************************
//************************************************
HttpMethod method = null;
// Relance de la requ�te si n�cessaire ...
DefaultMethodRetryHandler methodRetry = new DefaultMethodRetryHandler();
methodRetry.setRetryCount(3);
//En cas de succ�s d'envoi de requ�te, ne pas reessayer.
methodRetry.setRequestSentRetryEnabled(false);
// Create a method instance.
if(sRequestMethod.equalsIgnoreCase("get")){
method = new GetMethod(sUrl);
((GetMethod)method).setMethodRetryHandler(methodRetry);
}else{
//Target URL ...
method = new PostMethod(sUrl);
((PostMethod)method).setMethodRetryHandler(methodRetry);
((PostMethod)method).setRequestBody(sXmlMessageCoded);
}
// Tell the GET method to automatically handle authentication. The
// method will use any appropriate credentials to handle basic
// authentication requests. Setting this value to false will cause
// any request for authentication to return with a status of 401.
// It will then be up to the client to handle the authentication.
method.setDoAuthentication( true );
try {
// Execute the method.
int statusCode = client.executeMethod(method);
if (statusCode != HttpStatus.SC_OK) {
System.err.println("Method failed: " + method.getStatusLine());
}
// Read the response body.
byte[] responseBody = method.getResponseBody();
// Deal with the response.
// Use caution: ensure correct character encoding and is not binary data
setOutput(OUT_RESPONSE, responseBody);
logger.info(new String(responseBody));
} catch (HttpException e) {
System.err.println("Fatal protocol violation: " + e.getMessage());
e.printStackTrace();
} catch (IOException e) {
System.err.println("Fatal transport error: " + e.getMessage());
e.printStackTrace();
} finally {
// Release the connection.
method.releaseConnection();
}
}







---------------------------------
D�couvrez le nouveau Yahoo! Mail : 250 Mo d'espace de stockage pour vos mails !
Cr�ez votre Yahoo! Mail


Avec Yahoo! faites un don et soutenez le T�l�thon !

--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to