Click here to Skip to main content
15,905,963 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i receive ticket authtication code but error on
C#
WebResponse webResponse = webRequest.GetResponse();

error on The remote server returned an error: (405) Method Not Allowed.
my code give below..
C#
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());
}
}
}
}
Posted
Updated 13-Apr-13 4:31am
v2
Comments
anghan22 13-Apr-13 4:49am    
string URL = "GENERATED_URL_QUERY"; i run above code in localhost...

which url to write....?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900