我试图在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
更新
我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]"
尽管有线日志返回了此响应:Message: Bad HTTP/0.9 request type ('POST')
,但我可以直接向Endpoint发送帖子请求而没有任何问题。
这是对终端的直接发布请求:
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
这是输出结果:
- 状态:INIT =&gt; CONNECT句柄0x600057950;第1423行(连接#-5000)
- 重建网址为:http://192.168.1.50:1237/
- 添加了连接0.缓存现在包含1个成员
- 尝试5.202.129.107 ......
- TCP_NODELAY设置
- 状态:CONNECT =&gt; WAITCONNECT句柄0x600057950;第1475行(连接#0)
- 连接到192.168.1.50(192.168.1.50)端口1237(#0)
- 状态:WAITCONNECT =&gt; SENDPROTOCONNECT句柄0x600057950;第1592行(连接#0)
- 标记为[保持活动]:HTTP默认
- 状态:SENDPROTOCONNECT =&gt; DO处理0x600057950;第1610行(连接#0)
POST / HTTP / 1.1 主持人:http://192.168.1.50:1237 User-Agent:curl / 7.56.1 接受: / Content-Type:application / json 内容长度:197
- 上传已完全发送:197个字节中的197个
- 状态:DO =&gt; DO_DONE句柄0x600057950;第1689行(连接#0)
- 状态:DO_DONE =&gt; WAITPERFORM句柄0x600057950;第1814行(连接#0)
- 状态:WAITPERFORM =&gt; PERFORM句柄0x600057950;第1824行(连接#0)
- HTTP 1.0,假设身体后关闭
- 标记为[封闭]:身体后的HTTP / 1.0关闭&lt; HTTP / 1.0 200 OK&lt;服务器:BaseHTTP / 0.3 Python / 2.7.9&lt;日期:太阳,2018年1月14日07:53:37 GMT&lt;内容类型:application / json&lt;内容长度:2105
- 状态:PERFORM =&gt; DONE手柄0x600057950; 1993年(连接#0)
- multi_done
- 关闭连接0
- 缓存现在包含0个成员
- 过期已清除
当我将WSO2中的标题与curl的标题进行比较时,我无法弄清楚区别是什么。为什么在curl请求成功时WSO2请求失败?
答案 0 :(得分:1)
尝试在<send>
介体之前添加此内容。
<property name="FORCE_HTTP_1.0" value="true" scope="axis2"/>
答案 1 :(得分:0)
通过比较来自WSO2和curl的标题,我在curl标题Rebuilt URL to: http://192.168.1.50:1237/
中注意到了这一行。因此我改变了这个:
<endpoint>
<http method="post" uri-template="http://192.168.1.50:1237"/>
</endpoint>
对此:
<endpoint>
<http method="post" uri-template="http://192.168.1.50:1237/"/>
</endpoint>
答案 2 :(得分:0)
将以下属性添加到序列中:
FORCE_HTTP_CONTENT_LENGTH
COPY_CONTENT_LENGTH_FROM_INCOMING
这解决了这个问题,但原因还不得而知。
答案 3 :(得分:0)
来自您的电汇日志:
[2018-01-15 09:30:46,624] [EI-Core]调试-有线HTTP发送器I / O dispatcher-1 >>“
消息:错误的HTTP / 0.9请求类型('POST')。[\ n]” [2018-01-15 09:30:46,624] [EI-Core]调试-有线HTTP-Sender I / O dispatcher-1 >>“
错误代码说明:400 =错误的请求语法 或不受支持的方法。[\ n]“ [2018-01-15 09:30:46,624] [EI-Core]调试 -有线HTTP-Sender I / O调度程序-1 >>“ [\ n]”
注意:官方HTTP 0.9规范仅包含一种请求方法:GET。 您正在使用HTTP 0.9不支持的帖子
For more information about HTTP 0.9, refer to the original W3C HTTP specification.