【问题标题】:Sending vendor content type with jMeter throws IllegalArgumentException使用 jMeter 发送供应商内容类型会引发 IllegalArgumentException
【发布时间】:2021-04-01 00:35:54
【问题描述】:

我需要向使用多部分请求上传的文件添加自定义内容类型。为此,我将供应商内容类型application/vnd.anything.process+json;ver=1 作为该文件的MIME type。 不幸的是,jMeter 会抛出 IllegalArgumentException,因为它会将 ; 识别为内容类型规范中的无效字符。

如果不支持,那么如何发送内容类型包含; 的文件?我尝试使用邮递员并记录来自 jMeter 的传出 HTTP 调用,但失败并出现同样的异常。

java.lang.IllegalArgumentException: MIME type may not contain reserved characters
    at org.apache.http.util.Args.check(Args.java:36)
    at org.apache.http.entity.ContentType.create(ContentType.java:229)
    at org.apache.http.entity.ContentType.create(ContentType.java:241)
    at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.setupHttpEntityEnclosingRequestData(HTTPHC4Impl.java:1575)
    at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.handleMethod(HTTPHC4Impl.java:886)
    at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.sample(HTTPHC4Impl.java:641)
    at org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy.sample(HTTPSamplerProxy.java:66)
    at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1296)
    at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1285)
    at org.apache.jmeter.threads.JMeterThread.doSampling(JMeterThread.java:635)
    at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:558)
    at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:489)
    at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:256)
    at java.base/java.lang.Thread.run(Thread.java:830)

【问题讨论】:

    标签: java http jmeter mime-types content-type


    【解决方案1】:

    我得到了确认,这是 JMeter https://bz.apache.org/bugzilla/show_bug.cgi?id=65024 中的一个错误

    【讨论】:

      【解决方案2】:

      如果您绝对确定内容类型应该与您描述的完全一样,您可以将“客户端实现”切换为Java

      该设置位于HTTP Request 采样器的“高级”选项卡下:

      如果您想一次性更改所有 HTTP 请求采样器的客户端实现,您可以使用 HTTP Request Defaults 配置元素来完成

      【讨论】:

      • 谢谢,它部分解决了这个问题,但我不确定这是否是最好的主意。看起来 Java 实现不支持本地路径。表单还需要文件的 MIME 类型。应该可以发送更简单的一次,例如text/html; charset=UTF-8
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-10-13
      • 1970-01-01
      • 2013-09-02
      • 2015-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多