从 JMeter HTTPSampler 中删除 Content-Type header

Remove Content-Type header from JMeter HTTPSampler

我有一个 Web 应用程序的 JMeter (2.12 r1636949) 测试计划。线程组中的一个有问题的步骤是应用程序中远程 URI 的 HTTP 采样器需要 HTTP POST 而没有 Content-Type header 否则它会失败并出现 HTTP 500 错误。更改 Web 应用程序不是一个选项 - 使用 Fiddler 的流量检查显示浏览器能够执行此操作。

如何禁止从 JMeter HTTPSampler 发送 HTTP header Content-Type

我尝试过的:

上面的

None 导致 JMeter 成功调用远程资源,或者就此而言,避免发送 Content-Type。我比较了我在 View Results Tree 中看到的内容与 Fiddler 中记录的应用程序流量,我能看到的不同之处在于缺少 Content-Type.

来自 Fiddler 的原始请求示例我正在尝试在 JMeter 线程组中重新创建:

POST http://hostname/AppName/Flux/exec/Flux.fireAction HTTP/1.1
Accept: */*
Accept-Language: en-us
Referer: http://...referer url...
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/6.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; InfoPath.3; MS-RTC LM 8)
Host: hostname
Content-Length: 143
DNT: 1
Connection: Keep-Alive
Pragma: no-cache
Cookie: JSESSIONID=0000N1QLLDQCQycbKzkeaYFfCr3:18ujjmvjf

callCount=1
c0-scriptName=Flux
c0-methodName=fireAction
c0-id=9983_1420240552716
c0-param0=string:C187
c0-param1=string:1420240546765
xml=true

更新:

我能够通过一些 JMeter hack 成功调用服务器端 URL。默认情况下按照2.12 source (I set the sampler to HttpClient 4 to be sure) and scrutinizing the HTTP Sampler docs (particularly the MIME-Type notes for sending Files) I switched the sampler to the Parameters tab and moved the former Body Data contents to a text file now referenced as a single file to send with no Parameter Name and content type set to text/plain. However, the body content needs to be dynamic so a static file won't do - I need to reference a couple thread group variables. I'm currently researching how to read/write a file perhaps as a PreProcessor to set this content in a thread-safe manner, but this seems like a massive hack. I'm thinking this might be a worthwhile patch to allow Body Data with no content type, especially given the unsure TODO comment.

我通过在 HTTP 采样器之前添加一个 BeanShell 采样器来解决这个问题,它返回动态文本(使用 vars.get(...))作为它的 "response"。在那个采样器中,我使用 "Save Response to file" 监听器使用 a function for the per-virtual-user filename,将文件名存储为变量。在 HTTP 采样器中,我在 File Path 字段中使用了这个变量,Parameter Nametext/plain 用于 MIME-Type.

下面是 BeanShell 脚本,如果这对任何人有帮助,还有解决方法的屏幕截图。

//script for prepping Flux.fireAction request
sb = new StringBuilder();
NL = System.getProperty("line.separator");
sb.append("callCount=1").append(NL);
sb.append("c0-scriptName=Flux").append(NL);
sb.append("c0-methodName=fireAction").append(NL);
sb.append("c0-id=2728_1420218928279").append(NL);
sb.append("c0-param0=string:").append(vars.get("chibaIdFromRetrieveButton")).append(NL);
sb.append("c0-param1=string:").append(vars.get("chibaSessionKey")).append(NL);
sb.append("xml=true");
return sb.toString();