Created
October 29, 2008 20:30
-
-
Save deadprogram/20820 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private string Post(string username, string password, string url, string xml) | |
{ | |
string basicAuth = Convert.ToBase64String(Encoding.ASCII.GetBytes(String.Format("{0}:{1}", username, password))); | |
//create the web request | |
WebRequest request = WebRequest.Create(url); | |
request.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials; | |
request.Headers.Add("Authorization", "Basic " + basicAuth); | |
request.ContentType = "application/xml"; | |
request.ContentLength = xml.Length; | |
request.Method = "POST"; | |
//get the request stream | |
Stream stream = request.GetRequestStream(); | |
//convert the xml to an array of bytes | |
System.Text.Encoding enc = System.Text.Encoding.ASCII; | |
byte[] xmlArray = enc.GetBytes(xml); | |
//write the array to the request straem | |
stream.Write(xmlArray, 0, xmlArray.Length); | |
//get the response | |
WebResponse response = request.GetResponse(); | |
StreamReader reader = new StreamReader(response.GetResponseStream()); | |
return reader.ReadToEnd(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment