System.Net.HttpWebRequest
Added in .NET Framework 1.1
This is derived from the System.Net.WebRequest class.
GetResponse - Options
System.Net.HttpWebRequest oHttpWebRequest;
.Method = "GET"
.Method = "POST"
.AllowAutoRedirect = true;
.AutomaticDecompression = System.Net.DecompressionMethods.GZip;
.Credentials = System.Net.CredentialCache.DefaultCredentials
.Credentials = new System.Net.NetworkCredential("userid", "password")
.Credentials = new System.Net.NetworkCredential("userid", "password","INTRANET")
.CookieContainer = new System.Net.CookieContainer();
.ContentType = "text/xml";
.ContentType = "application/json";
.ContentLength =
.Encoding = Encoding.UTF8
.Headers.Add(System.Net.HttpRequestHeader.Accept, Accept);
.MaximumAutomaticRedirections = 200
.TimeOut = 10000
.TimeOut = (int)System.Timespan.FromMinutes(5).TotalMilliseconds;
.UserDefaultCredentials = true;
Example REST - GET
var result = null;
string restURL = "https://";
string returnText = "";
var request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(restURL);
request.AutomaticDecompression = System.Net.DecompressionMethods.GZip;
request.Method = "GET";
request.ContentType = "application/json";
request.CookieContainer = new System.Net.CookieContainer();
request.AllowAutoRedirect = true;
request.UseDefaultCredentials = true;
request.Timeout = (int)TimeSpan.FromMinutes(1).TotalMilliseconds;
using (var streamReader = new System.IO.StreamReader(request.GetResponse().GetResponseStream(), System.Text.Encoding.UTF8, true))
{
System.Web.Script.Serialization.JavaScriptSerializer js = new System.Web.Script.Serialization.JavaScriptSerializer();
string sText = streamReader.ReadToEnd();
result = ("")js.Deserialize(sText, typeof(""));
if (result != null)
{
returnText = result.getMethod; // this could return HTML or XML
}
}
System.IO.FileStream fileStream = System.IO.File.Create("C:\temp\myfile");
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(returnText);
fileStream.Write(bytes, 0, bytes.Count());
fileStream.Flush();
fileStream.Close();
Example REST - POST
var restService = null;
string restURL = "https://";
string returnText = "";
var request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(restURL);
request.AutomaticDecompression = System.Net.DecompressionMethods.GZip;
request.Method = "POST";
request.ContentType = "application/json";
request.CookieContainer = new System.Net.CookieContainer();
request.AllowAutoRedirect = true;
request.UseDefaultCredentials = true;
request.Timeout = (int)TimeSpan.FromMinutes(1).TotalMilliseconds;
System.IO.StreamWriter oStreamWriter;
oStreamWriter = new System.IO.StreamWriter(request.GetRequestStream(), System.Text.Encoding.ASCII);
oStreamWriter.Write(DATA);
oStreamWriter.Close();
using (var oStreamReader = new System.IO.StreamReader(request.GetResponse().GetResponseStream(), System.Text.Encoding.UTF8, true))
{
}
Example SOAP - GET
System.Net.HttpWebResponse oResponse;
oResponse = oHttpWebRequest.GetResponse
System.IO.StreamReader oStreamReader;
oStreamReader = new System.IO.StreamReader(oResponse.GetResponseStream, System.Text.Encoding.UTF8, true)
oStreamReader.ReadToEnd();
Example SOAP - POST
Methods
Abort | |
AddRange | |
BeginGetRequestStream | |
BeginGetResponse | |
EndGetRequestStream | |
EndGetResponse | |
GetObjectData | |
GetRequestStream | |
GetResponse |
Properties
Accept | |
Address | |
AllowAutoRedirect | |
AllowReadStreamBuffering | |
AllowWriteStreamBuffering | |
AutomaticDecompression | Indicates the type of decompression that is used. |
ClientCertificates | |
Connection | |
ConnectionGroupName | |
ContentLength | |
ContentType | |
ContinueDelegate | |
ContinueTimeout | |
CookieContainer | |
Credentials | |
Date | |
DefaultCachePolicy | |
DefaultMaximumErrorResponseLength | |
DefaultMaximumResponseHeadersLength | |
Expect | |
HaveResponse | |
Headers | |
Host | |
KeepAlive | |
MaximumAutomaticRedirections | |
MaximumResponseHeadersLength | |
MediaType | |
Method | |
Pipelined | |
PreAuthenticate | |
ProtocolVersion | |
Proxy | |
ReadWriteTimeout | |
Referer | |
RequestUri | |
SendChunked | |
ServerCertificateValidationCallback | |
ServicePoint | |
SupportsCookieContainer | |
Timeout | |
TransferEncoding | |
UnsafeAuthenticatedConnectionSharing | |
UseDefultCredentials | |
UserAgent |
© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext