Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / January 2007

Tip: Looking for answers? Try searching our database.

Issue in passing username and password credentials

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
San - 08 Jan 2007 05:16 GMT
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]
>     }
> }

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.