SHARE
TWEET

Untitled

a guest Dec 31st, 2014 264 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Net;
  6. using System.IO;
  7.  
  8. namespace WpfTestApplication
  9. {
  10.     public class MyWebRequest
  11.     {
  12.         private WebRequest request;
  13.         private Stream dataStream;
  14.  
  15.         private string status;
  16.  
  17.         public String Status
  18.         {
  19.             get
  20.             {
  21.                 return status;
  22.             }
  23.             set
  24.             {
  25.                 status = value;
  26.             }
  27.         }
  28.  
  29.        public MyWebRequest(string url, string method, string data)
  30. : this(url, method)
  31. {
  32.  
  33. if (request.Method == “POST”)
  34. {
  35. // Create POST data and convert it to a byte array.
  36. byte[] byteArray = Encoding.UTF8.GetBytes(data);
  37.  
  38. // Set the ContentType property of the WebRequest.
  39. request.ContentType = “application/x-www-form-urlencoded”;
  40.  
  41. // Set the ContentLength property of the WebRequest.
  42. request.ContentLength = byteArray.Length;
  43. // Get the request stream.
  44. dataStream = request.GetRequestStream();
  45.  
  46. // Write the data to the request stream.
  47. dataStream.Write(byteArray, 0, byteArray.Length);
  48.  
  49. // Close the Stream object.
  50. dataStream.Close();
  51. }
  52. else
  53. {
  54. String finalUrl = string.Format({0}{1}”, url, “?+ data);
  55. request = WebRequest.Create(finalUrl);
  56.  
  57. WebResponse response = request.GetResponse();
  58.  
  59. //Now, we read the response (the string), and output it.
  60. dataStream = response.GetResponseStream();
  61. }
  62.  
  63. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top