SMS API: ASP.NET / C# |
|
OverviewThe following C# function communicates with our server, makes an HTTP request and then returns our response. To use this function:
HttpWebRequest / HttpWebResponse
public string tm4b(string sURL, bool bEscapeURL, string sPostData)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
}string stmp = string.Empty; Uri httpUri = new Uri(sURL, bEscapeURL); try {
System.Text.ASCIIEncoding byteConverter = new System.Text.ASCIIEncoding();
}byte[] byte1 = byteConverter.GetBytes(sPostData); System.Net.HttpWebRequest hwRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(httpUri); hwRequest.ContentType = "application/x-www-form-urlencoded"; hwRequest.Method = "POST"; hwRequest.ContentLength = sPostData.Length; System.IO.Stream PostStream = hwRequest.GetRequestStream(); PostStream.Write(byte1, 0, byte1.Length); System.Net.HttpWebResponse hwResponse = (System.Net.HttpWebResponse)hwRequest.GetResponse(); System.IO.StreamReader sRead = new System.IO.StreamReader(hwResponse.GetResponseStream(), System.Text.Encoding.ASCII); while((stmp=sRead.ReadLine()) != nulll) {
sb.Append(stmp + "\r\n");
}PostStream.Close(); sRead.Close(); return sb.ToString(); catch(Exception ex) {
Response.Write(ex.Message);
}return string.Empty; |
|