【发布时间】:2018-01-13 11:23:08
【问题描述】:
我正在尝试在 WSO2 Enterprise Integrator 中使用 POST 方法调用 http-EndPoint。此 EndPoint 获取一个 JSON 对象作为输入,并返回一个 JSON 对象作为响应。
到目前为止,我在 Enterprise Integrator 中使用了各种类型的 http-EndPoints 没有任何问题,但是这个特定的 EndPoint 返回一条错误消息,我无法在 google 中找到任何关于它的线索。
这是我的 api:
<resource methods="POST" uri-template="/userInfo">
<inSequence>
<payloadFactory media-type="json">
<format>{"jsonrpc": "2.0", "params": {"auth_type": "ADMIN", "auth_name": "someName", "normal_username": "$1", "auth_pass": "myPassword"},"method": "user.MethodName", "id": 0}
</format>
<args>
<arg evaluator="json" expression="$.user"/>
</args>
</payloadFactory>
<property name="messageType" scope="axis2" type="STRING" value="application/json"/>
<property name="FORCE_HTTP_1.0" scope="axis2" type="STRING" value="true"/>
<send description="">
<endpoint>
<http method="post" uri-template="http://192.168.1.50:1237"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<send/>
</outSequence>
<faultSequence/>
</resource>
这是我在控制台中的错误消息:
[EI-Core] 错误 - TargetHandler HTTP 协议违规:不是有效的协议版本:
<head>对于:192.168.1.50:1237
更新
我enabled Wire Logs in WSO2来深入调查这个问题。这是日志输出:
[2018-01-15 09:30:46,621] [EI-Core] DEBUG - wire HTTP-Sender I/O dispatcher-1 << "POST HTTP/1.0[\r][\n]"
[2018-01-15 09:30:46,622] [EI-Core] DEBUG - wire HTTP-Sender I/O dispatcher-1 << "Expect: 100-continue[\r][\n]"
[2018-01-15 09:30:46,622] [EI-Core] DEBUG - wire HTTP-Sender I/O dispatcher-1 << "Content-Type: application/json[\r][\n]"
[2018-01-15 09:30:46,622] [EI-Core] DEBUG - wire HTTP-Sender I/O dispatcher-1 << "Content-Length: 196[\r][\n]"
[2018-01-15 09:30:46,622] [EI-Core] DEBUG - wire HTTP-Sender I/O dispatcher-1 << "Host: 192.168.1.50:1237[\r][\n]"
[2018-01-15 09:30:46,622] [EI-Core] DEBUG - wire HTTP-Sender I/O dispatcher-1 << "Connection: Keep-Alive[\r][\n]"
[2018-01-15 09:30:46,622] [EI-Core] DEBUG - wire HTTP-Sender I/O dispatcher-1 << "User-Agent: Synapse-PT-HttpComponents-NIO[\r][\n]"
[2018-01-15 09:30:46,622] [EI-Core] DEBUG - wire HTTP-Sender I/O dispatcher-1 << "[\r][\n]"
[2018-01-15 09:30:46,622] [EI-Core] DEBUG - wire HTTP-Sender I/O dispatcher-1 << "{"jsonrpc": "2.0", "params": {"auth_type": "ADMIN", "auth_name": "someName", "normal_username": "myUserName", "auth_pass": "myPassword", "remote_addr": "127.0.0.1"},"method": "user.MethodName", "id": 0}"
[2018-01-15 09:30:46,623] [EI-Core] DEBUG - wire HTTP-Sender I/O dispatcher-1 >> "<head>[\n]"
[2018-01-15 09:30:46,623] [EI-Core] DEBUG - wire HTTP-Sender I/O dispatcher-1 >> "<title>Error response</title>[\n]"
[2018-01-15 09:30:46,624] [EI-Core] DEBUG - wire HTTP-Sender I/O dispatcher-1 >> "</head>[\n]"
[2018-01-15 09:30:46,624] [EI-Core] DEBUG - wire HTTP-Sender I/O dispatcher-1 >> "<body>[\n]"
[2018-01-15 09:30:46,624] [EI-Core] DEBUG - wire HTTP-Sender I/O dispatcher-1 >> "<h1>Error response</h1>[\n]"
[2018-01-15 09:30:46,624] [EI-Core] DEBUG - wire HTTP-Sender I/O dispatcher-1 >> "<p>Error code 400.[\n]"
[2018-01-15 09:30:46,624] [EI-Core] DEBUG - wire HTTP-Sender I/O dispatcher-1 >> "<p>Message: Bad HTTP/0.9 request type ('POST').[\n]"
[2018-01-15 09:30:46,624] [EI-Core] DEBUG - wire HTTP-Sender I/O dispatcher-1 >> "<p>Error code explanation: 400 = Bad request syntax or unsupported method.[\n]"
[2018-01-15 09:30:46,624] [EI-Core] DEBUG - wire HTTP-Sender I/O dispatcher-1 >> "</body>[\n]"
虽然wire log返回了这个响应:Message: Bad HTTP/0.9 request type ('POST'),但是我可以直接向Endpoint发送post请求没有任何问题。
这是对端点的直接发布请求:
curl -v -H "Content-Type: application/json" -X POST -d '{"jsonrpc": "2.0", "params": {"auth_type": "ADMIN", "auth_name": "someName", "normal_username": "myUserName", "auth_pass": "myPassword", "remote_addr": "127.0.0.1"}, "method": "user.MethodName", "id": 0}' 192.168.1.50:1237
这是输出结果:
- 状态:初始化 => 连接句柄 0x600057950;第 1423 行(连接 #-5000)
- 将 URL 重建为:http://192.168.1.50:1237/
- 添加了连接 0。缓存现在包含 1 个成员
- 正在尝试 5.202.129.107...
- TCP_NODELAY 设置
- 状态:连接 => WAITCONNECT 句柄 0x600057950;第 1475 行(连接 #0)
- 连接到 192.168.1.50 (192.168.1.50) 端口 1237 (#0)
- 状态:WAITCONNECT => SENDPROTOCONNECT 句柄 0x600057950;第 1592 行(连接 #0)
- 标记为 [keep alive]:HTTP 默认
- 状态:SENDPROTOCONNECT => DO 句柄 0x600057950;第 1610 行(连接 #0)
POST / HTTP/1.1 主持人:http://192.168.1.50:1237 用户代理:curl/7.56.1 接受:/ 内容类型:应用程序/json 内容长度:197
- 上传已发送完毕:197 个字节中的 197 个
- 状态:DO => DO_DONE 句柄 0x600057950;第 1689 行(连接 #0)
- 状态:DO_DONE => WAITPERFORM 句柄 0x600057950;第 1814 行(连接 #0)
- 状态:WAITPERFORM => PERFORM 句柄 0x600057950;第 1824 行(连接 #0)
- HTTP 1.0,假设在正文之后关闭
- 标记为 [关闭]:HTTP/1.0 在正文后关闭
- 状态:执行 => 完成句柄 0x600057950;第 1993 行(连接 #0)
- multi_done
- 关闭连接 0
- 缓存现在包含 0 个成员
- 清除过期
当我将 WSO2 的标头与 curl 的标头进行比较时,我无法弄清楚有什么区别。为什么 WSO2 请求失败,而 curl 请求成功?
【问题讨论】:
-
可以直接用
curl -IL打后端,然后回复吗? -
@Bee 谢谢你的回复。我更新了我的问题。
-
好吧,我想让你做的是用一个真实的请求(即工作 url 和有效负载)运行该命令
-
@Bee 你能帮我做这件事吗?我试过这个:
curl -H "Content-Type: application/json" -X POST -d '{"jsonrpc": "2.0", "params": {"auth_type": "ADMIN", "auth_name": "someName", "normal_username": "myUserName", "auth_pass": "myPassword", "remote_addr": "127.0.0.1"}, "method": "user.MethodName", "id": 0}' 192.168.1.50:1237 -IL但它回应:Warning: You can only select one HTTP request method! You asked for both POST Warning: (-d, --data) and HEAD (-I, --head). -
你能运行这个并发布你得到的响应头吗?
curl -v -H "Content-Type: application/json" -X POST -d '{"jsonrpc": "2.0", "params": {"auth_type": "ADMIN", "auth_name": "someName", "normal_username": "myUserName", "auth_pass": "myPassword", "remote_addr": "127.0.0.1"}, "method": "user.MethodName", "id": 0}' 192.168.1.50:1237
标签: json http wso2 wso2carbon wso2ei