下面是我的java代码:
Authenticator.setDefault(new MyAuthenticator(){
public PasswordAuthentication getPasswordAuthentication() {
return (new PasswordAuthentication(username, password.toCharArray()));
}
});
URL url = new URL(RestUriConstants.BUSINESS_PROCESS_BASE + businessProcessName);
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setRequestProperty("Accept","application/json");
OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream());
writer.write(data);
writer.flush();
以上数据是:
action=start¶ms={"input":{"claimNo":"9","status":"open","customerName":"Rajesh"}}&createTask=false&parts=all
这工作正常。我在 Mule 中实现了同样的事情。我收到 400 错误。 我的骡子配置如下:
<set-variable variableName="url" value="#[json:url]" doc:name="Variable"></set-variable>
<set-variable variableName="param" value="action=start&params={"input":#[json:param]}&createTask=false&parts=all" doc:name="Variable"></set-variable>
<http:outbound-endpoint exchange-pattern="request-response" address="http://admin:admin@#[url.substring(7)]" method="GET" doc:name="HTTP">
<set-property propertyName="Content-Type" value="application/x-www-form-urlencoded"></set-property>
<set-property propertyName="Accept" value="application/json"></set-property>
<set-payload value="#[param]"/>
</http:outbound-endpoint>
<logger message="#['\n'+message.inboundProperties['http.status']]" level="INFO" doc:name="Logger"/>
我的 json 是:
{"url":"http://mysystem.com:8080/rest/processData ","param":{"claimNo":"9","status":"open", "customerName":"Rajesh"}}
谢谢。
最佳答案
如果要设置 POST 变量,请使用 POST 方法和 Map 类型的有效负载。像这样:
<set-payload value="#[['action':'start','params':param,'createTask':'false','parts':'all']]"/>
这里的变量“param”当然只是您作为 POST 变量之一的 JSON 字符串,而不是所有变量。
关于java - mule http 中的错误请求(400),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22475395/