Advertisement
Guest User

Untitled

a guest
Jul 20th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. public async Task<string> getData()
  2. {
  3. ASCIIEncoding encoding = new ASCIIEncoding();
  4. string postData = string.Format("school={0}&username={1}&password={2}", "schoolcode", "username", "password");
  5. byte[] data = encoding.GetBytes(postData);
  6.  
  7. WebRequest request = WebRequest.Create("https://example.com/login");
  8. request.Method = "POST";
  9. request.ContentType = "application/x-www-form-urlencoded";
  10. request.Headers["ContentLength"] = data.Length.ToString();
  11. Stream stream = await request.GetRequestStreamAsync();
  12. stream.Write(data, 0, data.Length);
  13. WebResponse response = await request.GetResponseAsync();
  14. stream = response.GetResponseStream();
  15. StreamReader sr = new StreamReader(stream);
  16. string res = await sr.ReadToEndAsync();
  17. return res;
  18. }
  19.  
  20. Stream stream = await request.GetRequestStreamAsync();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement