Click here to Skip to main content
15,897,519 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi There.

I have to send a query string from the front-end through to a SAP Business Connector in order to retrieve xml based results. The connection works fine but I need to send through a username and password for authentication. Please see the code below and assist where possible.

XML
var request2 = (HttpWebRequest)WebRequest.Create("http://IPADDRESS/invoke/Get/cs_GetTest/!?$xmldata=<ZVIN>PARAM</ZVIN>");

request2.Credentials = new NetworkCredential("USERNAME", "PASSWORD");
           

HttpWebResponse resp = (HttpWebResponse)request2.GetResponse();
           

StreamReader respStream = new StreamReader(resp.GetResponseStream());
           

string xmlFileString = respStream.ReadToEnd();
           

XmlDocument doc = new XmlDocument();
           

doc.LoadXml(xmlFileString);

           
respStream.Close();




Regards
Posted
Comments
Manas Bhardwaj 20-May-12 4:34am    
And the problem is?

request.Credentials = CredentialCache.DefaultCredentials;
 
Share this answer
 
Uri requestUri = null;
              Uri.TryCreate((linkUrl), UriKind.Absolute, out requestUri);
              NetworkCredential nc = new NetworkCredential(username, password);
              CredentialCache cache = new CredentialCache();
              cache.Add(requestUri, "Basic", nc);
              cache.Add(new Uri(linkUrl), "NTLM", new NetworkCredential("", ""));

              // Requesting query string
              HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(requestUri);
              request.Credentials = cache;

              // Getting response from WebRequest
              request.Method = WebRequestMethods.Http.Get;
              HttpWebResponse response = (HttpWebResponse)request.GetResponse();
              StreamReader respStream = new StreamReader(response.GetResponseStream());
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900