Monday, July 30, 2007

[C#.Net] Get Response Data from 3rd Party Web Service

WebRequest request;
WebResponse response;
string url = "https://www.nbdgateway.net/xmlgateway/affiliatelogin.do";

string postdata = "affiliatecode=backcheck&username=sa&password=pass&ssn=1&product=AIM";
request = WebRequest.Create(url);
request.Method = "POST";
//request.Referer = url;
request.ContentLength = postdata.Length;
request.ContentType = "application/x-www-form-urlencoded";
StreamWriter sw;
StreamReader sr;
// post data
sw = new StreamWriter(request.GetRequestStream());
sw.Write(postdata);
sw.Close();
//get result
response = request.GetResponse();
sr = new StreamReader(response.GetResponseStream());
string result = sr.ReadToEnd();
sr.Close();
textBox1.Text = result;

No comments: