【问题标题】:how to set no content-type using apache httpclient如何使用 apache httpclient 设置无内容类型
【发布时间】:2018-05-14 04:22:37
【问题描述】:

我在 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

有什么代码可以帮到我吗?

【问题讨论】:

    标签: apache httpclient


    【解决方案1】:

    参考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){
                }
    
            };
    

    【讨论】:

      猜你喜欢
      • 2013-09-01
      • 1970-01-01
      • 2016-09-28
      • 1970-01-01
      • 2013-05-29
      • 2010-11-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多