Guest User

Untitled

a guest
Jan 14th, 2016
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. WebRequest request = WebRequest.Create ("http://website.com/api/index.php");
  2. // Set the Method property of the request to POST.
  3. request.Method = "POST";
  4. // Create POST data and convert it to a byte array.
  5. string postData = "username="+username.Text+"&password="+pass.Text;
  6. byte[] byteArray = Encoding.UTF8.GetBytes (postData);
  7. // Set the ContentType property of the WebRequest.
  8. request.ContentType = "application/x-www-form-urlencoded";
  9. // Set the ContentLength property of the WebRequest.
  10. request.ContentLength = byteArray.Length;
  11. // Get the request stream.
  12. Stream dataStream = request.GetRequestStream ();
  13. // Write the data to the request stream.
  14. dataStream.Write (byteArray, 0, byteArray.Length);
  15. // Close the Stream object.
  16. dataStream.Close ();
  17. // Get the response.
  18. WebResponse response = request.GetResponse ();
  19. // Display the status.
  20. Console.WriteLine (((HttpWebResponse)response).StatusDescription);
  21. // Get the stream containing content returned by the server.
  22. dataStream = response.GetResponseStream ();
  23. // Open the stream using a StreamReader for easy access.
  24. StreamReader reader = new StreamReader (dataStream);
  25. // Read the content.
  26. string responseFromServer = reader.ReadToEnd ();
  27. // Display the content.
  28. Console.WriteLine (responseFromServer);
  29. // Clean up the streams.
  30. reader.Close ();
Add Comment
Please, Sign In to add comment