[英]C# REST WebClient POST Issue
我試圖通過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)
有人看到錯了嗎?
你不應該有?
在聲明查詢參數而不是&
http://jokr.info/api/v8/diary/add_item.xml?apikey=123456&item_id=1240&serving_id=1566
您缺少一個問號來標記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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.