简体   繁体   English

webapi2绑定不起作用

[英]webapi2 Binding not working

I'm new to webapi 2 and trying to get my api to bind to this call below. 我是webapi 2的新手,并尝试将我的api绑定到下面的此调用。

Can anyone see what I'm doing wrong? 谁能看到我在做什么错?

Call: https://blabla.azurewebsites.net/myjohndeere/authenticated/e33dd8f74c97474d86c75b00dd28ddf8?oauth_token=1539dccf-d935-4d9e-83be-e00f76cabbb9&oauth_verifier=B22dWL 致电: https//blabla.azurewebsites.net/myjohndeere/authenticated/e33dd8f74c97474d86c75b00dd28ddf8?oauth_token = 1539dccf-d935-4d9e-83be-e00f76cabbb9&oauth_verifier = B22dWL

[RoutePrefix("myjohndeere")]
public class ApiMyJohnDeereController : ApplicationController
{

    [HttpGet, Route("authenticated/{callbackId}")]
    [SwaggerResponse(HttpStatusCode.OK, Type = typeof(ApiResponseModel))]
    [SwaggerResponse(HttpStatusCode.InternalServerError, "An unknown error occurred")]
    [SwaggerResponse(HttpStatusCode.BadRequest, "Missing FieldMappings")]
    public IHttpActionResult Authenticated(string callbackId,[FromUri]string oauth_token, [FromUri]string oauth_verifier)
    {
        ...
    }

First of, you missed the 'api' in the route. 首先,您错过了路线中的“ api”。

Try it like this 像这样尝试

https://blabla.azurewebsites.net/api/myjohndeere/authenticated/e33dd8f74c97474d86c75b00dd28ddf8?oauth_token=1539dccf-d935-4d9e-83be-e00f76cabbb9&oauth_verifier=B22dWL https://blabla.azurewebsites.net/api/myjohndeere/authenticated/e33dd8f74c97474d86c75b00dd28ddf8?oauth_token=1539dccf-d935-4d9e-83be-e00f76cabbb9&oauth_verifier=B22dWL

Then, remove the FromUri attribute from your controller method. 然后,从控制器方法中删除FromUri属性。 The attribute is not needed when just reading querystring of value types. 仅读取值类型的查询字符串时,不需要该属性。

Try it like this 像这样尝试

public IHttpActionResult Authenticated(string callbackId, string oauth_token, string oauth_verifier)

问题是Azure API网关仍设置为使用PUT而不是GET。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM