G
Guest
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;
}
}
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;
}
}