Docusignapi Apache Http 4.5 StringBody构造函数未在请求中导出内容类型
使用Apache Http 4.5 MultipartEntityBuilder,似乎无法理解为什么StringBody(String,ContentType)构造函数实际上没有在请求表单正文中输出内容类型Docusignapi Apache Http 4.5 StringBody构造函数未在请求中导出内容类型,docusignapi,apache-httpclient-4.x,Docusignapi,Apache Httpclient 4.x,使用Apache Http 4.5 MultipartEntityBuilder,似乎无法理解为什么StringBody(String,ContentType)构造函数实际上没有在请求表单正文中输出内容类型 public HttpRequestBase build() throws UnsupportedEncodingException { HttpPost httpPost = new HttpPost("https://{server}/restapi/{apiVersion}/a
public HttpRequestBase build() throws UnsupportedEncodingException {
HttpPost httpPost = new HttpPost("https://{server}/restapi/{apiVersion}/accounts/{accountId}/envelopes");
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.setContentType(ContentType.MULTIPART_FORM_DATA);
builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
builder.setBoundary("AAA");
//add form body
builder.addPart(generateJsonFormBodyPart());
//add file body
builder.addPart(generateFileFormBodyPart()); //<--intentionally omitted
HttpEntity multipart = builder.build();
httpPost.setEntity(multipart);
return httpPost;
}
private FormBodyPart generateJsonFormBodyPart() throws UnsupportedEncodingException{
StringBody json = new StringBody(packageJson(), ContentType.APPLICATION_JSON); //<--THIS DOESN'T SEEM TO WORK
StringBuilder buffer = new StringBuilder();
buffer.append("form-data");
String contentDisposition = buffer.toString();
FormBodyPartBuilder partBuilder = FormBodyPartBuilder.create("application/json", json);
partBuilder.setField(MIME.CONTENT_DISPOSITION, contentDisposition);
FormBodyPart fbp = partBuilder.build();
return fbp;
}
public HttpRequestBase build()引发UnsupportedEncodingException{
HttpPost-HttpPost=newhttppost(“https://{server}/restapi/{apiVersion}/accounts/{accountId}/envelopes”);
MultipartEntityBuilder=MultipartEntityBuilder.create();
setContentType(ContentType.MULTIPART\u FORM\u DATA);
builder.setMode(HttpMultipartMode.BROWSER_兼容);
建造商。立法院(“AAA”);
//添加表单主体
addPart(generateJsonFormBodyPart());
//添加文件体
builder.addPart(generateFileFormBodyPart());//我确信这是处理StringBody时FormBodyPart.build()的Apache Http Mime中的一个错误。4.5.2发行说明中的证据表明,其他“body”类型的错误修复没有输出“Content Type”。我将记录一个缺陷
解决方法:
private FormBodyPart generateJsonFormBodyPart() throws UnsupportedEncodingException{
StringBody json = new StringBody(getMyJsonStuff(), ContentType.APPLICATION_JSON); //<--THE GOGGLES, THEY DO NOTHING!!
StringBuilder buffer = new StringBuilder();
buffer.append("form-data");
buffer.append("\r\n");
buffer.append("Content-Type: application/json"); //<--tack this on to the
String kludgeForDispositionAndContentType = buffer.toString();
FormBodyPartBuilder partBuilder = FormBodyPartBuilder.create("stuff", json);
partBuilder.setField(MIME.CONTENT_DISPOSITION, kludgeForDispositionAndContentType);
FormBodyPart fbp = partBuilder.build();
return fbp;
}
private FormBodyPart generateJsonFormBodyPart()引发不支持的编码异常{
StringBody json=新的StringBody(getMyJsonStuff(),ContentType.APPLICATION_json)//