Click here to Skip to main content
15,791,892 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:

C#
WebRequest request = WebRequest.Create("http://kanbanize.com/index.php/api/kanbanize/login/email/test1@gmail.com/pass/test1");

// 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.
dataStream.Close();
// Get the response.
WebResponse response = request.GetResponse();
// Display the status.
Console.WriteLine(((HttpWebResponse)response).StatusDescription);
// 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.
Console.WriteLine(responseFromServer);
// Clean up the streams.
reader.Close();
dataStream.Close();
response.Close();

also in my config i've added the following settings

XML
<system.net>
    <defaultProxy>
      <proxy usesystemdefault="False" bypassonlocal="True"/>
    </defaultProxy>
  </system.net>

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?
Posted
Updated 29-Jan-17 22:48pm
Comments
[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: http://kanbanize.com/index.php/api/kanbanize/login/email/test%40test.com/pass/test

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

Hi,

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

URL : http://kanbanize.com/index.php/api/kanbanize/login/email/test1%40gmail.com/pass/test1

You must add API Key
Quote:
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 : https://kanbanize.com/ctrl_integration[^]

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 : http://www.telerik.com/fiddler[^]

And compare two request using browser and using Exe
 
Share this answer
 
Comments
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