Hi,
I am facing a problem in posting Web request with username and password
credentials.
I am working on migrating Java client application to .Net which will send
request to Java servlet.
Java Client application code:
HttpClient httpclient;
httpclient = new HttpClient();
UsernamePasswordCredentials usernamepasswordcredentials = new
UsernamePasswordCredentials(s, s1);
httpclient.getState().setAuthenticationPreemptive(true);
httpclient.getState().setCredentials(null, null,
usernamepasswordcredentials);
Object obj = null;
I want info on .Net equivalent to Java's UsernamePasswordCredentials class .
This UsernamePasswordCredentials is different from .net's NetworkCredential.
I tried below code itz not working.
Please guide me on this issue.
Thanks
Santhosh
public static string HttpWebServiceRequest(string url, string userName,
string password, string xmlContent, string domain, int timeoutMS, int reqtype)
{
try
{
System.Net.ServicePointManager.CertificatePolicy = new
TrustAllCertificatePolicy();
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.Timeout = timeoutMS;
request.ContentType = "text/xml";
request.KeepAlive = true;
request.ContentLength = xmlContent.Length;
request.ProtocolVersion = HttpVersion.Version10;
if((userName != "") && (password != ""))
// I need to use some different class here.
request.Credentials = new NetworkCredential(userName, password, domain);
using (StreamWriter sw = new StreamWriter(request.GetRequestStream()))
{
sw.Write(xmlContent);
}
using (StreamReader sr = new
StreamReader(request.GetResponse().GetResponseStream()))
{
return sr.ReadToEnd();
}
}
catch (Exception e)
{
throw;
}
}
Jakob Christensen - 08 Jan 2007 08:59 GMT
It looks like you are using SSL?
MSDN states that NetworkCredential does not work for SSL. I have been
unable to find out what to do instead but you might want to try using this:
CredentialCache myCache = new CredentialCache();
NetworkCredential netCredential = new
NetworkCredential(UserName,SecurelyStoredPassword,Domain);
myCache.Add(new Uri(url),"Basic", netCredential);
myCache.Add(new Uri(url),"Digest", netCredential);
myCache.Add(new Uri(url),"Negotiate", netCredential);
myRequest.Credentials = myCache;
HTH, Jakob.

Signature
http://www.dotninjas.dk
> Hi,
>
[quoted text clipped - 58 lines]
> }
> }