简体   繁体   English

WebClient,不发送参数

[英]WebClient, doesn't send parameters

I try to get the token from my fogbugz website, folowing : 我尝试从我的fogbugz网站获取令牌,如下:

http://fogbugz.stackexchange.com/fogbugz-xml-api

I have : 我有 :

using (var wb = new WebClient())
{   
                var data = new NameValueCollection();
                data["cmd"] = HttpUtility.UrlEncode(cmdLogon);
                data["email"] = HttpUtility.UrlEncode(email);
                data["password"] = HttpUtility.UrlEncode(password);
                content = encoding.GetString(wb.UploadValues(url, "POST", data));
 }

Below the Server Response : 在服务器响应下方:

<?xml version="1.0" encoding="UTF-8"?><response><error code="1">Nom d'utilisateur ou mot de passe incorrect</error></response>

I can see the request in IIS logs but parameters are absent. 我可以在IIS日志中看到请求,但是没有参数。

What I'm doing wrong? 我做错了什么?

edit : I'm sure parameters are correct cause I tested In the browser and it work well. 编辑:我确定参数正确,原因是我在浏览器中进行了测试,并且效果很好。

I ran this with Fiddler, and your code sends a request with the following content in the request body: 我与Fiddler一起运行了,您的代码在请求正文中发送了具有以下内容的请求:

cmd=logon&email=test-email&password=test-password

Instead, I believe you should be sending this information in the query string as per the documentation (see the "Logging On" section): 相反,我相信您应该根据文档在查询字符串中发送此信息(请参见“登录”部分):

http://www.example.com/api.asp?cmd=logon&email=xxx@example.com&password=BigMac

If you want to use a NameValueCollection to build your querystring, this answer provides a way to do that. 如果要使用NameValueCollection来构建查询字符串,则此答案提供了一种实现方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM