admin管理员组

文章数量:1203976

row body is printed in Postman as TradeSha=https%3A%2F%2Fenv.example%2Fpayments%2FRedirectHandler%2F1002%3FtId%3D100201195%26token%3D9c8dce5b-ddbb-4190-9cbe-3da45fad50d2

Location header is printed as ;token=unknown-token

For this request: POST /mpggateway HTTP/1.1 Host: core-mocks-qa.bglobale Content-Type: application/x-www-form-urlencoded Content-Length: 154

TradeSha=https%3A%2F%2Fenv.example%2Fpayments%2FRedirectHandler%2F1002%3FtId%3D100201195%26token%3D9c8dce5b-ddbb-4190-9cbe-3da45fad50d2

And this mapping in WireMock:

        {
        "request": {
          "urlPattern": "/mpggateway",
          "method": "POST",
          "headers": {
            "Content-Type": {
              "matches": "application/x-www-form-urlencoded.*"
            }
          }
        },
        "response": {
          "status": 302,
          "headers": {
            "Location": "={{regexExtract request.body 'tId%3D([a-f0-9\\-]+)' 1 default='unknown-token'}}&token={{regexExtract request.body 'token%3D([a-f0-9\\-]+)' 1 default='unknown-token'}}"
          },
          "body": "Raw Body: {{request.body}}",
          "delayDistribution": {
            "type": "uniform",
            "lower": 500,
            "upper": 750
          }
        },
        "metadata": {
          "description": "cool"
        }
      }

I've tried using different regex and also formData helper.

row body is printed in Postman as TradeSha=https%3A%2F%2Fenv.example.com%2Fpayments%2FRedirectHandler%2F1002%3FtId%3D100201195%26token%3D9c8dce5b-ddbb-4190-9cbe-3da45fad50d2

Location header is printed as https://env.example.com/payments/PSPRedirectHandler/1002?tId=unknown-token&token=unknown-token

For this request: POST /mpggateway HTTP/1.1 Host: core-mocks-qa.bglobale.com Content-Type: application/x-www-form-urlencoded Content-Length: 154

TradeSha=https%3A%2F%2Fenv.example.com%2Fpayments%2FRedirectHandler%2F1002%3FtId%3D100201195%26token%3D9c8dce5b-ddbb-4190-9cbe-3da45fad50d2

And this mapping in WireMock:

        {
        "request": {
          "urlPattern": "/mpggateway",
          "method": "POST",
          "headers": {
            "Content-Type": {
              "matches": "application/x-www-form-urlencoded.*"
            }
          }
        },
        "response": {
          "status": 302,
          "headers": {
            "Location": "https://env.example.com/payments/RedirectHandler/1002?tId={{regexExtract request.body 'tId%3D([a-f0-9\\-]+)' 1 default='unknown-token'}}&token={{regexExtract request.body 'token%3D([a-f0-9\\-]+)' 1 default='unknown-token'}}"
          },
          "body": "Raw Body: {{request.body}}",
          "delayDistribution": {
            "type": "uniform",
            "lower": 500,
            "upper": 750
          }
        },
        "metadata": {
          "description": "cool"
        }
      }

I've tried using different regex and also formData helper.

Share Improve this question edited Jan 21 at 5:55 DarkBee 15.6k8 gold badges70 silver badges114 bronze badges asked Jan 21 at 5:31 lionheartlionheart 43712 silver badges34 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

The "1" in the handlebars should refer to a variable that should be used afterwards. For example - {{regexExtract request.body 'token%3D([a-f0-9\\-]+)' 1 default='unknown-token'}} should be {{regexExtract request.body 'token%3D([a-f0-9\\-]+)' 'parts' default='unknown-token'}}{{parts.1}}

Now it works

本文标签: regexRedirect url from xwwwformurlencoded request doesn39t work out of the boxStack Overflow