【发布时间】:2016-11-07 12:14:48
【问题描述】:
我试图通过 Postman 调用 Put 方法,但总是出现错误:
“405 Method Not Allow”和“Message”:“请求的资源不支持 http 方法 'PUT'。”
我正在使用 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();
}
当我通过 Postman 调用 Put 方法时,我调用“http://localhost:XXXX/multilanguage/resources/2/En”。 “2”和“En”是我代码中的前两个参数。而且我还在 Postman 请求正文中使用 x-www-form-urlencoded 类型指定了“text”参数值:key = text, value = Test!这个 put 方法假设将 temp.Content 值更新为“Test!”。但是,它总是因我上面提到的错误而失败。
我错过了什么吗?
【问题讨论】:
标签: c# http asp.net-web-api2 postman