将参数发送到服务器

本文关键字:服务器 参数 | 更新日期: 2023-09-27 18:16:20

嗨,我需要从windows phone 7应用程序发布一些数据到web服务器,我有以下url

someurl/devices.json

我需要发送两个参数

"externalDeviceId"  and "platform" as parameters
有谁能告诉我怎么做吗?我一直在尝试这样做
   WebClient client = new WebClient();
      client.UploadStringCompleted += new UploadStringCompletedEventHandler(webClient_UploadStringCompleted);
      client.Headers["Content-Type"] = "application/x-www-form-urlencoded";
      client.Encoding = Encoding.UTF8;
      string argument = "externalDeviceId=123456789987654321"+"&platform=wp7"
      client.UploadStringAsync(new Uri("someurl/devices.json"), "POST", argument);

,但我得到一个web异常在webClient_UploadStringCompleted回调。

我也试过这样做

soemurl/devices.json&externalDeviceId=123456789987654321&Platform= windowphone7,但这不能工作,得到一个错误404

让我知道我哪里做错了。这是在Windows phone 7上。

它可以工作,如果我注释掉标题和编码行它可以工作

WebClient client = new WebClient();
client.UploadStringCompleted += new 
UploadStringCompletedEventHandler(webClient_UploadStringCompleted);
// client.Headers["Content-Type"] = "application/x-www-form-urlencoded";
 //client.Encoding = Encoding.UTF8;
 string argument = "externalDeviceId=123456789987654321"+"&platform=wp7"
 client.UploadStringAsync(new Uri("soemurl    
 /devices.json"), "POST", argument);

感谢Tetsujin no Oni san的帮助…从上一天开始,我一直在兜圈子,只是进行了一些讨论,这有助于解决这个问题

将参数发送到服务器

使用给定的API URI,如果您使参数实际上遵循查询字符串参数的正确协议,会发生什么?

http://api.maxchatter.com/75b7bb32e5fc752546263a/devices.json?externalDeviceId=123456789987654321&平台= windowsphone7

使用以下代码

 WebClient client = new WebClient();
client.UploadStringCompleted += new 
UploadStringCompletedEventHandler(webClient_UploadStringCompleted);
// client.Headers["Content-Type"] = "application/x-www-form-urlencoded";
//client.Encoding = Encoding.UTF8;
string argument = "externalDeviceId=123456789987654321"+"&platform=wp7"
client.UploadStringAsync(new Uri("soemurl    
/devices.json"), "POST", argument);