User interface 如何解决来自Swagger UI的错误请求?
我使用的是Swagger用户界面(版本:3.9.59)。 我编写了一个名为GetProduct的ServiceStack合同。代码如下User interface 如何解决来自Swagger UI的错误请求?,user-interface,swagger,bad-request,User Interface,Swagger,Bad Request,我使用的是Swagger用户界面(版本:3.9.59)。 我编写了一个名为GetProduct的ServiceStack合同。代码如下 [Route("/products/{Id}", Verbs="GET", Notes = "Gets the product by id", Summary = "Object that doesn't need to be created directly")] [Api("Get the product by id")] [ApiResponse(Http
[Route("/products/{Id}",
Verbs="GET",
Notes = "Gets the product by id",
Summary = "Object that doesn't need to be created directly")]
[Api("Get the product by id")]
[ApiResponse(HttpStatusCode.NotFound, "No products have been found in the repository")]
public class GetProduct
{
[ApiMember(AllowMultiple = false,
DataType = "int",
Description = "Represents the ID passed in the URI",
IsRequired = false,
Name = "Id",
ParameterType = "int",
Verb = "GET")]
[ApiAllowableValues("family", typeof(int))] //Enum
public int Id { get; set; }
}
在我通过Google Chrome运行Swigger UI之后,我看到了图1。我在图1中的文本框中输入了一些产品id,如1,然后单击按钮“试用!”
但我得到了一个例外。详情如下
[Route("/products/{Id}",
Verbs="GET",
Notes = "Gets the product by id",
Summary = "Object that doesn't need to be created directly")]
[Api("Get the product by id")]
[ApiResponse(HttpStatusCode.NotFound, "No products have been found in the repository")]
public class GetProduct
{
[ApiMember(AllowMultiple = false,
DataType = "int",
Description = "Represents the ID passed in the URI",
IsRequired = false,
Name = "Id",
ParameterType = "int",
Verb = "GET")]
[ApiAllowableValues("family", typeof(int))] //Enum
public int Id { get; set; }
}
返回的请求URL是“{Id}?api_key=special key”
返回的响应正文是
{
"ResponseStatus": {
"ErrorCode": "RequestBindingException",
"Message": "Unable to bind request",
"StackTrace": " in ServiceStack.WebHost.Endpoints.RestHandler.GetRequest(IHttpRequest httpReq, IRestPath restPath)\r\n in ServiceStack.WebHost.Endpoints.RestHandler.ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, String operationName)"
}
}
Date: Tue, 08 Dec 2015 09:44:13 GMT
Server: Microsoft-IIS/8.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Content-Type: application/json; charset=utf-8
Cache-Control: private
X-SourceFiles: =?UTF-8?B?RDpcWWFuZ0xpXOWFrOWPuOi1hOaWmVxQcm9qZWN0c1xTZXJ2aWNlU3RhY2tc5a2m5Lmg6LWE5paZXOS5puexjea6kOeggVxTZXJ2aWNlU3RhY2sgU3VjY2luY3RseVzop6Pljovku7bvvIjlj6/kv67mlLnvvIlcQ2hhcHRlcjEyIC0gRG9jdW1lbnRpbmcgV2ViIFNlcnZpY2VzXFNlcnZpY2VTdGFjay5TdWNjaW5jdGx5Lkhvc3RccHJvZHVjdHNce0lkfQ==?=
Content-Length: 346
返回的响应代码为400
返回的响应标题为
{
"ResponseStatus": {
"ErrorCode": "RequestBindingException",
"Message": "Unable to bind request",
"StackTrace": " in ServiceStack.WebHost.Endpoints.RestHandler.GetRequest(IHttpRequest httpReq, IRestPath restPath)\r\n in ServiceStack.WebHost.Endpoints.RestHandler.ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, String operationName)"
}
}
Date: Tue, 08 Dec 2015 09:44:13 GMT
Server: Microsoft-IIS/8.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Content-Type: application/json; charset=utf-8
Cache-Control: private
X-SourceFiles: =?UTF-8?B?RDpcWWFuZ0xpXOWFrOWPuOi1hOaWmVxQcm9qZWN0c1xTZXJ2aWNlU3RhY2tc5a2m5Lmg6LWE5paZXOS5puexjea6kOeggVxTZXJ2aWNlU3RhY2sgU3VjY2luY3RseVzop6Pljovku7bvvIjlj6/kv67mlLnvvIlcQ2hhcHRlcjEyIC0gRG9jdW1lbnRpbmcgV2ViIFNlcnZpY2VzXFNlcnZpY2VTdGFjay5TdWNjaW5jdGx5Lkhvc3RccHJvZHVjdHNce0lkfQ==?=
Content-Length: 346
谷歌浏览器返回了以下信息。
图:
如何解决上述问题