Last active
August 29, 2015 14:01
-
-
Save nicklasos/7f68f45129d8a981087f to your computer and use it in GitHub Desktop.
C# Common functions
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 struct MainPage | |
{ | |
public string Threads { get; set; } | |
public List<Pager> Pages { get; set; } | |
} | |
public struct Pager | |
{ | |
private string filename; | |
public string Filename | |
{ | |
get | |
{ | |
return Page == 0 ? filename.Replace("0", "wakaba") : filename; | |
} | |
set | |
{ | |
filename = value; | |
} | |
} | |
public int Page { get; set; } | |
} | |
string json = @" | |
{ | |
'threads': 'bla', | |
'pages': [ | |
{ | |
'filename': '/b/0.json', | |
'page': 0 | |
}, | |
{ | |
'filename': '/b/1.json', | |
'page': 1 | |
}, | |
{ | |
'filename': '/b/2.json', | |
'page': 2 | |
}, | |
{ | |
'foo': 'baaaar' | |
} | |
] | |
} | |
"; | |
MainPage mainPage = JsonConvert.DeserializeObject<MainPage>(json); | |
Console.WriteLine(mainPage.Threads); | |
foreach (Pager currentPage in mainPage.Pages) | |
{ | |
Console.WriteLine(currentPage.Filename); | |
} |
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
string text = string.Empty; | |
using (StreamReader streamReader = new StreamReader("wakaba.json", Encoding.UTF8)) | |
{ | |
text = streamReader.ReadToEnd(); | |
} |
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 (WebClient webClient = new WebClient()) | |
{ | |
webClient.QueryString.Add("param1", "value1"); | |
webClient.QueryString.Add("param2", "value2"); | |
string result = webClient.DownloadString("http://theurl.com"); | |
} |
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
string URI = "http://www.myurl.com/post.php"; | |
string myParameters = "param1=value1¶m2=value2¶m3=value3"; | |
using (WebClient wc = new WebClient()) | |
{ | |
wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded"; | |
string HtmlResult = wc.UploadString(URI, myParameters); | |
} |
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
string sURL = "http://www.microsoft.com"; | |
WebRequest wrGETURL = WebRequest.Create(sURL); | |
WebResponse objResponse = wrGETURL.GetResponse(); | |
Stream objStream = objResponse.GetResponseStream(); | |
StreamReader objReader = new StreamReader(objStream); | |
string response = objReader.ReadToEnd(); | |
objStream.Close(); | |
objReader.Close(); | |
objResponse.Close(); | |
Console.WriteLine(response); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment