简体   繁体   English

如何在 JMeter 中使用 post 请求发送 xml 文件

[英]How to send xml file with post request in JMeter

I am using JMeter 2.13 .我正在使用 JMeter 2.13 。 I am sending xml as attachment in Post request我在 Post 请求中将 xml 作为附件发送

Parameters authenticity_token :- hjghjsdfhjghsjkdg, utf8 :- ✓参数authenticity_token :- hjghjsdfhjghsjkdg, utf8 :- ✓

HTTP Header Manager :- Accept : text/xml, C ontent Type :- text/xml HTTP 标头管理器:-接受:text/xml,内容类型:- text/xml

Port 80 , Method Post, Protocol http 80端口方法Post,协议http

I am adding file address as in attachement我在附件中添加文件地址

System.getProperty("user.dir") + File.separator + "NewXMLEvent.xml" System.getProperty("user.dir") + File.separator + "NewXMLEvent.xml"

I want to send xml as file rather than parameter or body, this xml file is created with code, its not working , Do I need to add any other header info, or data我想将 xml 作为文件而不是参数或正文发送,这个 xml 文件是用代码创建的,它不起作用,我是否需要添加任何其他标题信息或数据

response I am getting is XML content expected我得到的响应是XML content expected

Your approach won't work.你的方法行不通。

If you need to upload a file - valid values are:如果您需要上传文件 - 有效值为:

  1. Full path to the file (recommended)文件的完整路径(推荐)
  2. Relative path to the file文件的相对路径
  3. JMeter Property which is set during JMeter launch or via user.properties file在 JMeter 启动期间或通过 user.properties 文件设置的 JMeter 属性

If you need to send XML file content :如果您需要发送 XML 文件内容

  1. Switch to "Body Data" tab切换到“身体数据”选项卡
  2. Use __FileToString() function to specify source XML file location使用__FileToString()函数指定源 XML 文件位置

    FiletoString 函数示例

You can even combine __FileToString() function with__Beanshell() function to dynamically get the file path like:您甚至可以将 __FileToString() 函数与__Beanshell()函数结合起来动态获取文件路径,例如:

${__FileToString(${__BeanShell(System.getProperty("user.dir") + File.separator + "NewXMLEvent.xml",)},,)}

I know, the syntax is scary, that's why I use Function Helper Dialog for generating functions.我知道,语法很可怕,这就是为什么我使用Function Helper Dialog来生成函数。

See How to Use JMeter Functions posts series for more information on above and other useful JMeter functions.有关上述和其他有用的 JMeter 函数的更多信息,请参阅 如何使用 JMeter 函数系列帖子。

I tried the above three steps posted in Answer 1 and none of them actually worked.我尝试了答案 1 中发布的上述三个步骤,但没有一个真正起作用。 I am testing a REST API.我正在测试 REST API。

My XML file has about 5000 lines, so it would be convenient if I could just point do 1. above the full path to file.我的 XML 文件有大约 5000 行,所以如果我能在文件的完整路径上方点 do 1. 会很方便。 However, this did not work.然而,这并没有奏效。 I also had three other parameters, other than the one called content and had to supply the value.我还有其他三个参数,除了一个叫做 content 的参数,并且必须提供值。

In JMeter 3.0, with Method as POST, under Parameters I supplied: param1 value1 param2 value2 param3 value3 For content, I opened the XML file with an Editor and then Select All, then Copy.在 JMeter 3.0 中,方法为 POST,在我提供的参数下: param1 value1 param2 value2 param3 value3 对于内容,我使用编辑器打开 XML 文件,然后选择全部,然后复制。 In JMeter for Value->Detail - This opens up an scratch pad.在 JMeter for Value->Detail - 这会打开一个便笺簿。 Paste XML content in that.在其中粘贴 XML 内容。 Just for content, I checked Encoding and Equals.只是为了内容,我检查了编码和等于。

This way I was able to send my XML file.这样我就可以发送我的 XML 文件。 Hope this works for others as well希望这也适用于其他人

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM