1. Get
1 2 3 4 5 6 7 8 9 10 11 12 |
using System.Net; //add string username = "john"; string urlAddress = "http://www.yoursite.tld/somepage.php?username=" + username; using (WebClient client = new WebClient()) { // this string contains the webpage's source string pagesource = client.DownloadString(urlAddress); } |
2. Post
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
string username = "john"; string referer = "myprogram"; string urlAddress = "http://www.yoursite.tld/somepage.php"; using (WebClient client = new WebClient()) using System.Net; //add using System.Collections.Specialized; /add { NameValueCollection postData = new NameValueCollection() { { "username", username }, //order: {"parameter name", "parameter value"} { "referer", referer } }; // client.UploadValues returns page's source as byte array (byte[]) // so it must be transformed into a string string pagesource = Encoding.UTF8.GetString(client.UploadValues(urlAddress, postData)); } |
참조 : https://codingvision.net/c-sending-data-using-get-or-post