2017-10-20 48 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 刪除

順利通過

測試