JMeter将请求主体中的所有CRLF替换为LF。

huangapple go评论77阅读模式
英文:

JMeter replace all CRLF in the request body with LF

问题

将以下内容翻译为中文:
我是JMeter的新手,我想在将JMeter HTTP请求体发送到服务器之前将所有的CRLF字符替换为LF。我需要为线程组中的所有请求执行此操作。请有人指导一下。

英文:

I am new to JMeter, I want to replace all CRLF characters with LF in the JMeter HTTP request body before it is sent to the server.
I need to do this for all requests in a thread group. Can someone please guide.

答案1

得分: 0

.jmx脚本基本上是XML文件,因此您可以使用任何合适的文本编辑器将CRLF更改为LF,甚至Notepad++也能做到

如果您仍在寻找仅适用于JMeter的解决方案,您可以通过在HTTP请求采样器的相同级别添加JSR223预处理器并将以下代码放入“脚本”区域来实现:

def data = sampler.getArguments().getArgument(0).getValue().replaceAll('\r\n', '\n')
def argument = new org.apache.jmeter.protocol.http.util.HTTPArgument('', data, '')
def arguments = new org.apache.jmeter.config.Arguments()
arguments.addArgument(argument)
sampler.setArguments(arguments)

有关JMeter中Groovy脚本的更多信息:Apache Groovy:Groovy用于什么?

英文:

Well, JMeter .jmx scripts are basically XML files so you can change CRLF to LF using any suitable text editor, even Notepad++ is capable of doing it

If you're still looking for a JMeter-only solution - you can do it by adding a JSR223 PreProcessor at the same level as your HTTP Request samplers and putting the following code into "Script" area:

def data = sampler.getArguments().getArgument(0).getValue().replaceAll('\r\n', '\n')
def argument = new org.apache.jmeter.protocol.http.util.HTTPArgument('', data, '')
def arguments = new org.apache.jmeter.config.Arguments()
arguments.addArgument(argument)
sampler.setArguments(arguments)

More information on Groovy scripting in JMeter: Apache Groovy: What Is Groovy Used For?

huangapple
  • 本文由 发表于 2023年5月17日 19:47:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/76271760.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定