【问题标题】:C# REST WebClient POST IssueC# REST WebClient POST 问题
【发布时间】:2012-09-12 15:22:54
【问题描述】:

我正在尝试通过 POST 方法将数据上传到 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)

有谁知道出了什么问题?

【问题讨论】:

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


    【解决方案1】:

    在声明查询参数之前你不应该有?而不是&

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

    【讨论】:

    • 现在我明白了:addserving.UploadStringAsync(new Uri("http://jokr.info/api/v8/diary/add_item.xml?apikey=123456"), "&item_id=1240&serving_id=1566") 我必须使用逗号将 POST 与 GET 分开。
    【解决方案2】:

    您缺少一个问号来标记 hte 参数集合的开始。

    改变

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-02-20
      • 1970-01-01
      • 1970-01-01
      • 2010-10-06
      • 1970-01-01
      • 2021-12-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多