Last active
December 20, 2015 01:08
-
-
Save kad1r/6046439 to your computer and use it in GitHub Desktop.
HttpPost
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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