我正在尝试在 WSO2 Enterprise Integrator 中使用POST方法调用http-EndPoint 。此 EndPoint 获取JSON对象作为输入并返回 JSON 对象作为响应。
到目前为止,我在 Enterprise Integrator 中使用了各种类型的 http-EndPoints 没有任何问题,但是这个特定的 EndPoint 返回一条错误消息,我无法在谷歌中找到任何关于它的线索。
这是我的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
更新
我在 WSO2 中启用了 Wire Logs来深入调查这个问题。这是日志输出:
[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返回了这个response:,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 接受:/ 内容类型:application/json 内容长度:197
- 上传完全发送:197 个字节中的 197 个
- 状态:DO => DO_DONE 句柄 0x600057950;第 1689 行(连接 #0)
- 状态:DO_DONE => WAITPERFORM 句柄 0x600057950;第 1814 行(连接 #0)
- 状态:WAITPERFORM => PERFORM 句柄 0x600057950;第 1824 行(连接 #0)
- HTTP 1.0,假设在正文之后关闭
- 标记为 [closure]:HTTP/1.0 在正文 < HTTP/1.0 200 OK 后关闭 < 服务器:BaseHTTP/0.3 Python/2.7.9 < 日期:Sun,2018 年 1 月 14 日 07:53:37 GMT < 内容类型:应用程序/ json <内容长度:2105 <
- 状态:执行 => 完成句柄 0x600057950;第 1993 行(连接 #0)
- 多完成
- 关闭连接 0
- 缓存现在包含 0 个成员
- 过期清除
当我将 WSO2 的标头与 curl 的标头进行比较时,我无法弄清楚有什么区别。为什么 WSO2 请求失败而 curl 请求成功?