WSO2 APIM 4.1.0通过cURL调用服务API无响应问题咨询
问题排查结论
你使用的调用URL是正确的,WSO2 APIM 4.1.0版本Publisher v2接口创建API的POST路径默认就是/api/am/publisher/v2/apis,本地调用使用https://127.0.0.1:9443前缀也符合默认端口配置。
无响应、无错误码返回不是URL错误导致的,按以下顺序排查即可:
- 先验证token与连通性
你当前生成的access token需要携带apim:api_create权限范围,如果token权限不足、或者生成时scope填错,部分版本会出现请求挂起不返回的情况。可以先用同样的Authorization头调用GET接口https://127.0.0.1:9443/api/am/publisher/v2/apis?limit=1,如果能正常返回API列表,说明token和网络连通性没有问题。 - 修正请求体参数错误
你提供的data.json里存在多处占位符参数不符合接口校验规则,是导致请求静默失败的核心原因:operations[0].authType不能填占位值string,合法取值为Application & Application User、Application、Noneoperations[0].target不能填占位值string,需要填写实际的API资源路径,比如通配所有路径填/*即可operations[0].scopes字段是API资源绑定的业务scope,不是管理端接口权限scope,新建API无自定义业务scope时直接传空数组operations[0].usedProductIds无关联API产品时直接传空数组,不要传string占位值
可以先用下面这个最小可用的请求体测试:
{ "policies": ["Unlimited"], "visibility": "PUBLIC", "visibleRoles": [], "visibleTenants": [], "cacheTimeout": 300, "endpointConfig": { "endpoint_type": "http", "sandbox_endpoints": {"url": "http://maps.google.com/maps/api/directions/"}, "production_endpoints": {"url": "http://maps.google.com/maps/api/directions/"} }, "subscriptionAvailability": null, "subscriptionAvailableTenants": [], "operations": [ { "target": "/*", "verb": "POST", "authType": "Application & Application User", "throttlingPolicy": "Unlimited", "scopes": [] } ], "responseCachingEnabled": false, "isDefaultVersion": true, "businessInformation": { "technicalOwner": "ApiCreator", "technicalOwnerEmail": "ApiCreator@pizzashack.com", "businessOwner": "ApiPublisher", "businessOwnerEmail": "ApiPublisher@pizzashack.com" }, "transport": ["http", "https"], "tags": ["phone", "multimedia", "mobile"], "provider": "admin", "version": "Beta", "description": "Calculates directions between locations", "name": "GoogleDirectionsAPI", "context": "/googledirections" }
- 优化curl命令方便排查
你当前使用的curl命令没有开启verbose模式、也没有设置超时,出现请求挂起时看不到具体卡点,建议替换为下面的命令测试,可以看到完整的请求握手、发送、响应过程:
curl -v -k --connect-timeout 10 -H "Authorization: Bearer <access-token>" -H "Content-Type: application/json" -X POST -d @data.json https://127.0.0.1:9443/api/am/publisher/v2/apis
注:如果替换请求体后仍然无响应,先检查WSO2服务端的
wso2carbon.log日志文件,接口校验失败的报错都会打印在该日志中,路径为<APIM安装目录>/repository/logs/wso2carbon.log
内容的提问来源于stack exchange,提问作者viggnah
相关产品推荐
相关产品推荐

