Click here to Skip to main content
15,849,180 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi I'm trying to send a POST request to Login to a website based on the MSDN example I have this code:

WebRequest request = WebRequest.Create("");

// Set the Method property of the request to POST.
request.Method = "POST";
// Create POST data and convert it to a byte array.
//string postData = "This is a test that posts this string to a Web server.";
string postData = "This is a login test";
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
// 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;
// Get the request stream.
Stream dataStream = request.GetRequestStream();
// Write the data to the request stream.
dataStream.Write(byteArray, 0, byteArray.Length);
// Close the Stream object.
// Get the response.
WebResponse response = request.GetResponse();
// Display the status.
// Get the stream containing content returned by the server.
dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd();
// Display the content.
// Clean up the streams.

also in my config i've added the following settings

      <proxy usesystemdefault="False" bypassonlocal="True"/>

but when i try to run this I'm getting this error: "Unable to connect to the remote server" any ideas to help me out please?
Updated 29-Jan-17 22:48pm
[no name] 3-Jul-14 9:25am    
It might work if you give it a good URL.
pmcm 3-Jul-14 9:42am    
retried with this a valid url and I'm still getting the same error, anything else I can try? also if i'm just trying to test the login to this site do I need the to set postData?
pmcm 3-Jul-14 9:26am    
whats wrong with that url? the kanbanize site states that the login url should be in this format:

Missed the special char conversion in the string - let me retry!
pmcm 3-Jul-14 9:37am    
retried with this a valid url and I'm still getting the same error, anything else I can try? also if i'm just trying to test the login to this site do I need the to set postData?
ZurdoDev 3-Jul-14 9:41am    
1. Reply to the comment so that the user is notified.
2. If I go to your modified url in the browser directly I get an error "Invalid API Key." I believe you should be asking them.

1 solution


You should post API Key with request. API key should provide in Request Body.


You must add API Key
API key

To authenticate yourself to the system, you need to specify the API key as a header. To generate such a key, login to the system and go to the My account->API panel. If your role allows it, you will be able to access the tab and generate a unique key.

Note: Header name must be "apikey".

Go Through this Page for more info :[^]

Now check are you able to connect that URL from that PC where you running the exe.
IF Yes : Then check 1. Proxy required or not any firewall is there or not

To Compare where its stuck you can use Fiddler :[^]

And compare two request using browser and using Exe
Share this answer
pmcm 3-Jul-14 10:05am    
I read that on the website but didn't think it was applicable to a login request, especially as the APIKey is an output from this function

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