Secure HttpWebRequest so I can send credentials possible?

violabrick

New Member
I have the following code which connects to my php server and retrieves data from it. The only thing is, I need to send the username and password securely from this webrequest to the PHP server. Looking at the docs for the webrequest class, there is a credentials property as well as a preauthenticate property. I'm assuming these are for the network credentials (all my users are in AD).Is it possible to secure this post request with credentials or is this just a bad idea? I've also found SetBasicAuthHeader - I'll read up on this and see if it might help. All traffic will be on SSL from ASPX site to the PHP site\[code\] // variables to store parameter values string url = "https://myphpserver.php"; // creates the post data for the POST request string postData = "http://stackoverflow.com/questions/14609559/Username=" + username + "&Password=" + "&UID=" + UniqueRecID; // create the POST request HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url); webRequest.Method = "POST"; webRequest.ContentType = "application/x-www-form-urlencoded"; webRequest.ContentLength = postData.Length; // POST the data using (StreamWriter requestWriter2 = new StreamWriter(webRequest.GetRequestStream())) { requestWriter2.Write(postData); } // This actually does the request and gets the response back HttpWebResponse resp = (HttpWebResponse)webRequest.GetResponse(); string responseData = http://stackoverflow.com/questions/14609559/string.Empty; using (StreamReader responseReader = new StreamReader(webRequest.GetResponse().GetResponseStream())) { // dumps the HTML from the response into a string variable responseData = responseReader.ReadToEnd(); }\[/code\]
 
Back
Top