尝试从浏览器和邮递员调用基本REST GET操作。
在浏览器中,URL为http://localhost:7800/restrequest_api/v1/4
其中4是我要传递的UserNumber。
它正在被成功地调用。
但是从PostMan我无法调用它。
尝试了http://localhost:7800/restrequest_api/v1,Content-Type头作为application/x-www-form-urlencoded,选择的主体为x-www-form-urlencoded,键为UserNumber,值为4
这是错误的
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>404 Not Found</title>
</head>
<body>
<h1>404 Not Found</h1>
<p>
BIP6311E: REST API ''RESTRequest_API'' does not support method ''GET'' for URL
''http://localhost:7800/restrequest_api/v1''.
</p>
<hr>
</body>
</html>请注意: CORS已启用:
mqsichangeproperties TESTNODE_hghatak -e default -o HTTPConnector -n corsEnabled -v true
mqsichangeproperties TESTNODE_hghatak -b httplistener -o HTTPConnector -n corsEnabled -v true
mqsistop TESTNODE_hghatak
mqsistart TESTNODE_hghatak下面是用于开发的Swagger文件:
{
"swagger" : "2.0",
"info" : {
"title" : "RESTRequest_API",
"version" : "1.0.0",
"description" : "RESTRequest_API"
},
"paths" : {
"/{UserNumber}" : {
"get" : {
"operationId" : "getUser",
"responses" : {
"200" : {
"description" : "The operation was successful.",
"schema" : {
"$ref" : "#/definitions/Output"
}
}
},
"produces" : [ "application/json" ],
"description" : "Retrieve User",
"parameters" : [ {
"required" : true,
"name" : "UserNumber",
"in" : "path",
"type" : "string"
} ]
}
}
},
"basePath" : "/restrequest_api/v1",
"definitions" : {
"Output" : {
"type" : "object",
"properties" : {
"firstName" : {
"type" : "string"
},
"lastName" : {
"type" : "string"
},
"userDetails" : {
"type" : "string"
},
"userNumber" : {
"type" : "string"
}
}
}
},
"host" : "localhost:7800"
}有什么问题吗?
发布于 2020-04-06 15:46:33
只需在POSTMAN中选择GET作为您的操作,在postman中的BODY选项卡中选择"none“选项。确保您在postman中使用的URL与在浏览器中使用的相同,即
解释:
您的swagger文件指示正在执行GET操作,因此不需要发送有效负载。因此,选择内容类型是不适用的。在swagger文件的parameters部分中,提到了" In“:path”,这意味着您必须在url中传递一个路径参数,即 ,其中4是示例中的路径参数。您可以查看下面的postman链接,该链接提供了有关发送参数=> https://learning.postman.com/docs/postman/sending-api-requests/requests/#sending-parameters的更多详细信息
https://stackoverflow.com/questions/61032619
复制相似问题