The following classes replace the previous version of HTTP web
requests and responses.
Example: Old request and response format |
---|
Previously you would use:
System.Net.HttpWebRequest
request = (System.Net.HttpWebRequest) System.Net.WebRequest.Create( url
); to make the request.
System.Net.HttpWebResponse
response = (System.Net.HttpWebResponse) request.GetResponse(); for the
response.
//REQUEST
System.Net.HttpWebRequest request = (System.Net.HttpWebRequest) System.Net.WebRequest.Create( url );
request.Method = "POST";
request.Accept = "application/json";
request.ContentType = "application/json";
request.ContentLength = dataArray.Length;
//if (needAuth) request.Headers["Authorization"] = "Basic ";
// OUTPUT
System.IO.Stream outputStream = request.GetRequestStream();
outputStream.Write(dataArray, 0, dataArray.Length);
outputStream.Close();
// RESPONSE
System.Net.HttpWebResponse response = (System.Net.HttpWebResponse) request.GetResponse();
System.IO.StreamReader inputStream = new System.IO.StreamReader(response.GetResponseStream(), System.Text.Encoding.GetEncoding(1252));
// PROCESS
string readData = inputStream.ReadToEnd();
|
Example: New request and response format |
---|
Going forward, replace:
SafeHttpWebRequest
request = new SafeHttpWebRequest( url ); to make the request.
SafeHttpWebResponse response =
request.GetSafeResponse(); for the response.
// REQUEST
SafeHttpWebRequest request = new SafeHttpWebRequest( url );
request.Method = "POST";
request.Accept = "application/json";
request.ContentType = "application/json";
request.ContentLength = dataArray.Length;
//if (needAuth) request.Headers["Authorization"] = "Basic ";
// OUTPUT
System.IO.Stream outputStream = request.GetRequestStream();
outputStream.Write(dataArray, 0, dataArray.Length);
outputStream.Close();
// RESPONSE
SafeHttpWebResponse response = request.GetSafeResponse();
System.IO.StreamReader inputStream = new System.IO.StreamReader(response.GetResponseStream(), System.Text.Encoding.GetEncoding(1252));
// PROCESS
string readData = inputStream.ReadToEnd();
|