我試圖通過郵遞員調用Put方法並始終出錯:
「405方法不允許」和「消息」:「請求的資源不支持http方法'PUT'。「錯誤「405方法不允許」在郵遞員中調用Put方法時使用body參數
我正在使用DocumentDB和C#。這裏是我的代碼:
[Route("multilanguage/Resources/{id}/{Language}")]
[HttpPut]
public async Task<IHttpActionResult> UpdateResource(string Id, string Language, string text)
{
client = new DocumentClient(new Uri(EndPoint), AuthKey);
var collectionLink = UriFactory.CreateDocumentCollectionUri(DatabaseId, CollectionId);
var query = new SqlQuerySpec("SELECT * FROM MultiLanguage as m where m.id = @pmId",
new SqlParameterCollection(new SqlParameter[] { new SqlParameter { Name = "@pmId", Value = Id } }));
Document doc = client.CreateDocumentQuery<Document>(
collectionLink, query).AsEnumerable().FirstOrDefault();
List<Models.Translations> d = doc.GetPropertyValue<List<Models.Translations>>("Translations");
Models.Translations temp = d.Find(p => p.Language == Language);
temp.Content = text;
temp.LastModified = DateTimeOffset.Now;
temp.ModifiedBy = "admin";
doc.SetPropertyValue("Translations", d);
Document updated = await client.ReplaceDocumentAsync(doc);
return Ok();
}
當我調用Put方法throught郵差,我稱之爲 「http://localhost:XXXX/multilanguage/resources/2/En」。 「2」和「En」是我的代碼中的前兩個參數。我還使用x-www-form-urlencoded類型在郵遞員請求正文中指定「文本」參數值:key = text,value = Test!這個put方法假設將temp.Content值更新爲「Test!」。但是,它總是因我上面提到的錯誤而失敗。
我在這裏錯過了什麼嗎?
謝謝!這樣可行! –
太棒了!祝你今天愉快 –