Skip to content

Instantly share code, notes, and snippets.

@kad1r
Last active December 20, 2015 01:08
Show Gist options
  • Save kad1r/6046439 to your computer and use it in GitHub Desktop.
Save kad1r/6046439 to your computer and use it in GitHub Desktop.
HttpPost
public static string GetHtmlPage(string _url)
{
String strResult;
WebResponse objResponse;
WebRequest objRequest = HttpWebRequest.Create(_url);
objResponse = objRequest.GetResponse();
using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
{
strResult = sr.ReadToEnd();
sr.Close();
}
return strResult;
}
public static string HttpPostRequest(string _url, string post)
{
var encoding = new ASCIIEncoding();
byte[] data = encoding.GetBytes(post);
WebRequest request = WebRequest.Create(_url);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;
Stream stream = request.GetRequestStream();
stream.Write(data, 0, data.Length);
stream.Close();
WebResponse response = request.GetResponse();
String result;
using (var sr = new StreamReader(response.GetResponseStream()))
{
result = sr.ReadToEnd();
sr.Close();
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment