Created
February 12, 2015 16:29
-
-
Save AlbinoDrought/70fae7d134026df1bd38 to your computer and use it in GitHub Desktop.
c# gargl
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
using System; | |
using System.Net; | |
using System.IO; | |
public class Sample-Site | |
{ | |
public string Function1 (string topic,string variableParamValue,string subtopic) | |
{ | |
string url = "http://www.samplesite.com/@topic@/@subtopic@" + "?staticParam=value1&variableParam=" + variableParamValue + ""; | |
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); | |
req.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; | |
req.Method = "GET"; | |
req.UserAgent = "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.76 Safari/537.36"; | |
req.Headers.Add("Accept-Encoding", "gzip,deflate,sdch"); | |
HttpWebResponse resp = (HttpWebResponse)req.GetResponse(); | |
int responseCode = (int)resp.StatusCode; | |
Console.WriteLine("Sending 'GET' request to URL : " + url); | |
Console.WriteLine("Response Code : " + responseCode); | |
string response; | |
using(StreamReader input = new StreamReader(resp.GetResponseStream())) | |
{ | |
response = input.ReadToEnd(); | |
} | |
Console.WriteLine(response.ToString()); | |
return response.ToString(); | |
} | |
public string Function2 (string variableParamValue,string otherHeaderValue) | |
{ | |
string url = "http://www.samplesite.com/posturl" + "?"; | |
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); | |
req.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; | |
req.Method = "POST"; | |
req.UserAgent = "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.76 Safari/537.36"; | |
req.Headers.Add("Accept-Encoding", "gzip,deflate,sdch"); | |
req.Headers.Add("Some-Other-Header", otherHeaderValue); | |
string postData = "staticParam=value2&variableParam=" + variableParamValue + ""; | |
using(StreamWriter writer = new StreamWriter(req.GetRequestStream())) | |
{ | |
writer.Write(postData); | |
writer.Flush(); | |
} | |
HttpWebResponse resp = (HttpWebResponse)req.GetResponse(); | |
int responseCode = (int)resp.StatusCode; | |
Console.WriteLine("Sending 'GET' request to URL : " + url); | |
Console.WriteLine("Response Code : " + responseCode); | |
string response; | |
using(StreamReader input = new StreamReader(resp.GetResponseStream())) | |
{ | |
response = input.ReadToEnd(); | |
} | |
Console.WriteLine(response.ToString()); | |
return response.ToString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment