Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Net;
- using System.IO;
- namespace WpfTestApplication
- {
- public class MyWebRequest
- {
- private WebRequest request;
- private Stream dataStream;
- private string status;
- public String Status
- {
- get
- {
- return status;
- }
- set
- {
- status = value;
- }
- }
- public MyWebRequest(string url, string method, string data)
- : this(url, method)
- {
- if (request.Method == “POST”)
- {
- // Create POST data and convert it to a byte array.
- byte[] byteArray = Encoding.UTF8.GetBytes(data);
- // Set the ContentType property of the WebRequest.
- request.ContentType = “application/x-www-form-urlencoded”;
- // Set the ContentLength property of the WebRequest.
- request.ContentLength = byteArray.Length;
- // Get the request stream.
- dataStream = request.GetRequestStream();
- // Write the data to the request stream.
- dataStream.Write(byteArray, 0, byteArray.Length);
- // Close the Stream object.
- dataStream.Close();
- }
- else
- {
- String finalUrl = string.Format(“{0}{1}”, url, “?” + data);
- request = WebRequest.Create(finalUrl);
- WebResponse response = request.GetResponse();
- //Now, we read the response (the string), and output it.
- dataStream = response.GetResponseStream();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement