发送POST请求以登录网站 [英] Sending a POST request to login to a website

查看:216
本文介绍了发送POST请求以登录网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我正在尝试发送POST请求以登录基于MSDN示例的网站我有此代码:



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("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

<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?

推荐答案

你好,



你应该发布API密钥请求。 API密钥应在请求正文中提供。



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



你必须添加API密钥

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密钥



要对系统进行身份验证,您需要将API密钥指定为标头。要生成此类密钥,请登录系统并转到我的帐户 - >API面板。如果您的角色允许,您将能够访问该选项卡并生成一个唯一的密钥。



注意:标题名称必须是apikey。

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".





浏览此页面了解更多信息: https://kanbanize.com/ctrl_integration [ ^ ]



现在检查一下你能从运行exe的那台PC上连接那个URL。

如果是:然后检查1.是否需要代理服务器是否有防火墙



要比较卡住的地方你可以使用Fiddler: http://www.telerik.com/提琴手 [ ^ ]



使用浏览器并使用Exe



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


这篇关于发送POST请求以登录网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆