Create HTTP request and receive response using asp.net C#
1.Simple http request
Uri objurl = new Uri(url);
WebRequest objWebRequest = WebRequest.Create(objurl);
WebResponse objWebResponse = objWebRequest.GetResponse();
Stream objstream = objWebResponse.GetResponseStream();
StreamReader objStreamReader = new StreamReader(objstream);
string strHtml = objStreamReader.ReadToEnd();
2.HTTP Post request and response
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("https://clinet-url.com/sub/Activate");
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.Credentials = CredentialCache.DefaultNetworkCredentials;
req.ClientCertificates.Add(clint_certificate);
strNewReqValue = strFormValues + "&mssdn=" + msisdn + "&srv=" + Service + "&user=username";
req.ContentLength = strNewReqValue.Length;
StreamWriter stOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
stOut.Write(strNewReqValue);
stOut.Close();
StreamReader stIn = new StreamReader(req.GetResponse().GetResponseStream());
Res = stIn.ReadToEnd();
Response = Res.ToString();
stIn.Close();
0 comments:
Post a Comment