2017-10-20 93 views
0
// curl -v -S -u root:abc123456 -F'notification={"applicationId":"229396","schemaId":"229506","topicId":"98315","type":"USER"};type=application/json' "http://wy.com/" | python -mjson.tool 

CloseableHttpClient client = HttpClients.createDefault(); 
HttpPost post = new HttpPost(url); 
MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); 
StringBody comment = new StringBody(param,ContentType.APPLICATION_JSON); 
reqEntity.addPart("notification", comment); 
post.setEntity(reqEntity); 
post.addHeader("Authorization", getHeader(authString)); 

上面是我的curl和Java代码。如何使用java来模拟CURL传输参数?

我已经设置了通知类型,但在运行的时候,仍然有错误的400提示:

400 
Required request part 'notification' is not present 

是否有任何人谁可以帮我看看问题出在哪里?

回答

0

的问题已经解决了

StringBody comment = new StringBody(param,ContentType.APPLICATION_JSON); 

更改到以下一个

StringBody comment = new StringBody(param,ContentType.create("application/json")); 

而且,HttpMultipartMode.BROWSER_COMPATIBLE 删除

顺利通过

测试
相关问题