英文:
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?
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论