Below is an eample for HTTP POST (with additional HTTP header)
{ ....
try
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create
("http://xxxx/Mt.do");
request.Method = "POST";
string parameter = "HTTP body content";
byte[] byteArray = Encoding.UTF8.GetBytes(parameter);
request.Headers.Add("Encrypt", strMD5);
request.Headers.Add("Mobile", "xxxx");
request.Headers.Add("Vas", "xxxx");
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (HttpStatusCode.OK == response.StatusCode)
{
dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string line;
while ((line = reader.ReadLine()) != null)
{
MessageBox.Show(line.ToString());
}
dataStream.Close();
response.Close();
}
else MessageBox.Show("Response code not OK");
....
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
...
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment