C#REST WebClient POST问题

时间:2012-09-12 15:22:55

标签: c# windows-phone-7 rest post webclient

我正在尝试通过POST-Method将数据上传到REST服务,但由于某些原因服务器告诉我:

  

System.Net.WebException:远程服务器返回错误:NotFound。

我正在尝试使用以下代码上传数据:

WebClient addserving = new WebClient();
addserving.Credentials = new NetworkCredential(username.Text, passwort.Password);

addserving.Encoding = System.Text.Encoding.GetEncoding("ISO-8859-1");
addserving.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
addserving.UploadStringAsync(new Uri("http://jokr.info/api/v8/diary/add_item.xml&apikey=123456&item_id=1240&serving_id=1566"), "POST");
addserving.UploadStringCompleted += new UploadStringCompletedEventHandler(serving_UploadStringCompleted);

API的文档告诉我这样发布:

Rate Limit: Yes
HTTP Methods: POST
Authentication: Basic authentication (Username or E-Mail and Password)
Formats: xml
Parameters: format, apikey [GET], activity_id [POST], activity_duration [POST], activity_kj [POST], timestamp [POST] (optional)

有人看到了什么问题吗?

2 个答案:

答案 0 :(得分:3)

在说明查询参数而不是?

之前,您不应该有&

http://jokr.info/api/v8/diary/add_item.xml?apikey=123456&item_id=1240&serving_id=1566

答案 1 :(得分:1)

你错过了一个问号来标记参数集的开头。更改

http://jokr.info/api/v8/diary/add_item.xml&apikey=123456&item_id

http://jokr.info/api/v8/diary/add_item.xml?apikey=123456&item_id