简体   繁体   English

如何在 Jmeter 中定义正则表达式?

[英]How to define a Regular Expression in Jmeter?

my problem is that I need to define a regular expression in Jmeter in order to make a DELETE method in my page.我的问题是我需要在 Jmeter 中定义一个正则表达式,以便在我的页面中创建一个 DELETE 方法。 The real problem is that I cannot delete a specific token with an ID.真正的问题是我无法删除带有 ID 的特定令牌。

I defined a regular Expression which his name is "uidprofesor" that refers to the token.我定义了一个正则表达式,他的名字是“uidprofesor”,指的是令牌。 This token, when I try to delete it manually and catch the request, I get the following code in the Raw Response Data:这个令牌,当我尝试手动删除它并捕获请求时,我在原始响应数据中得到以下代码:

{"headers":
  {"Location":["/api/profesores/5c745065-3155-4ff7-ac65-7699a36f611c"],
              "X-afppApp-alert":["afppApp.profesor.created"],
              "X-afppApp-params":["5c745065-3155-4ff7-ac65-7699a36f611c"]},
              "body":{"id":"5c745065-3155-4ff7-ac65-7699a36f611c",
              "nif":"12345678Q",
              "name":"jmeter_122",
              "firstSurname":"jmeter_122",
              "secondSurname":"",
              "address":"",
              "postalCode":"",
              "telephone":"",
              "mobile":"",
              "email":"",
              "dateInsert":"24/04/2019"
  },
 "statusCode":"CREATED",
 "statusCodeValue":201
}

, where I assume that "5c745065-3155-4ff7-ac65-7699a36f611c" is the ID. ,我假设“5c745065-3155-4ff7-ac65-7699a36f611c”是ID。

If I wanted to define "uidprofesor" to catch that ID what should I define in the regular erxpression?如果我想定义“uidprofesor”来捕获该 ID,我应该在常规 erxpression 中定义什么?

I tried defining the regular expression like:我尝试定义正则表达式,如:

{"headers":"(.+?)"
{"headers":{"Location":"(.+?)"
{"Location":"(.+?)"

But nothing.但没什么。 It shows the Default Value: NOT_FOUND and does not delete the selected token.它显示默认值:NOT_FOUND 并且不会删除选定的令牌。

I let you here some extra info:我让你在这里一些额外的信息:

regular expression ${uidprofesor} = {"headers":"(.+?)"

In the HTTP Request the Path is:在 HTTP 请求中,路径是:

https://desa1eap7.asturias.es/afpp-back/${uidprofesor}

If I do the deletion manually, in Google Chrome Developer Tab, It returns:如果我手动删除,在 Google Chrome Developer Tab 中,它返回:

Requested URL: https://desa1eap7.asturias.es/afpp-back/api/profesores

If you need more info just ask it.如果您需要更多信息,请询问。 Thanks.谢谢。

Use jMeter JSON Extractor: https://jmeter.apache.org/usermanual/component_reference.html#JSON_Extractor使用 jMeter JSON 提取器: https ://jmeter.apache.org/usermanual/component_reference.html#JSON_Extractor

It uses JsonPath https://goessner.net/articles/JsonPath/它使用 JsonPath https://goessner.net/articles/JsonPath/

$.headers.Location[0]

Check online here https://jsonpath.com/在此处在线查看https://jsonpath.com/

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

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