我在apache httpclient(最新版本)上面临一个问题
我正在使用
builder.addPart("_sid", new StringBody("abcd"));
构建表单部分,但在服务器中,请求信息为:
Content-Disposition: form-data; name="_sid"
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 8bit
我希望http客户端不发送两行:
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 8bit
是否有任何代码可以帮助我?
答案 0 :(得分:0)
参考In apache http client, how to keep the Content-Type in a StringBody as empty or null?,我得到钥匙:
- FormBodyPart bodyPart = new FormBodyPart("_sid", new StringBody(sessionID, ContentType.DEFAULT_TEXT)) {
@Override
protected void generateContentType(ContentBody body) {
}
@Override
protected void generateTransferEncoding(final ContentBody body){
}
};