public static void Post(string url, Dictionary<string,string> postData) { WebRequest request = WebRequest.Create(url); HttpRequesterState requestState = new HttpRequesterState(); request.Method = "POST"; // Convert POST data to a byte array. string postString = Json.Serialize(postData); byte[] byteArray = Encoding.UTF8.GetBytes(postString); Stream dataStream = request.GetRequestStream(); // 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; // Write the data to the request stream. dataStream.Write(byteArray, 0, byteArray.Length); // Close the Stream object. dataStream.Close(); // Put the request into the state object so it can be passed around. requestState.Request = request; // Issue the async request. request.BeginGetResponse(new AsyncCallback(RespCallback), requestState); }
public static void Get(string url) { WebRequest request = WebRequest.Create(url); HttpRequesterState requestState = new HttpRequesterState(); request.Method = "GET"; // Put the request into the state object so it can be passed around. requestState.Request = request; // Issue the async request. request.BeginGetResponse(new AsyncCallback(RespCallback), requestState); }