// 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));
Above is my curl and Java code.
I have already set up notification type, but when running, there are still 400 of the error prompts:
400
Required request part 'notification' is not present
Is there anyone who can help me see where the problem is?
The problem has been solved
StringBody comment = new StringBody(param,ContentType.APPLICATION_JSON);
Change to the following one
StringBody comment = new StringBody(param,ContentType.create("application/json"));
And, HttpMultipartMode.BROWSER_COMPATIBLE remove
The test passed successfully
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.