WebResponse webResponse = webRequest.GetResponse();
namespace TechnetSamples { class Program { static void Main(string[] args) { //You must request a ticket using HTTPS protocol string URLAuth = "https://technet.rapaport.com/HTTP/Authenticate.aspx"; WebClient webClient = new WebClient(); NameValueCollection formData = new NameValueCollection(); formData["Username"] = "myUser"; formData["Password"] = "myPassword"; byte[] responseBytes = webClient.UploadValues(URLAuth, "POST", formData); string ResultAuth = Encoding.UTF8.GetString(responseBytes); //After receiving an encrypted ticket, you can use it to authenticate your session. //Now you can choose to change the protocol to HTTP so it works faster. //Sample URL query - http://technet.rapaport.com/HTTP/RapLink/download.aspx?ShapeIDs=1&Programmatically=yes string URL = "GENERATED_URL_QUERY"; WebRequest webRequest = WebRequest.Create(URL); webRequest.Method = "POST"; webRequest.ContentType = "application/x-www-form-urlencoded"; webRequest.Headers.Add(System.Net.HttpRequestHeader.AcceptEncoding, "gzip"); Stream reqStream = webRequest.GetRequestStream(); string postData = "ticket=" + ResultAuth; byte[] postArray = Encoding.ASCII.GetBytes(postData); reqStream.Write(postArray, 0, postArray.Length); reqStream.Close(); WebResponse webResponse = webRequest.GetResponse(); StreamReader str; //The following is to check if the server sending the response supports Gzip if (webResponse.Headers.Get("Content-Encoding") != null && webResponse.Headers.Get("Content-Encoding").ToLower() == "gzip") { str = new StreamReader(new GZipStream(webResponse.GetResponseStream(), CompressionMode.Decompress)); } else { str = new StreamReader(webResponse.GetResponseStream()); } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)