【问题标题】:Unable to decode form field data in karate framework [duplicate]无法在空手道框架中解码表单字段数据[重复]
【发布时间】:2021-10-06 11:51:00
【问题描述】:

我最近了解了空手道,在这方面的工作非常棒。 我被一个问题困住了,并从各种网站寻找解决方案,但没有帮助

场景: 给定网址“https://test.payu.in/_payment” 并形成字段 surl = '/payu/web-response/17703721?appVersion=null&clientId=web-client/1.0' 当方法 POST 然后状态 302

当我们点击上述请求时,表单字段值被编码为 'surl=%2Fpayu%2Fweb-response%2F17703721%3FappVersion%3Dnull%26clientId%3Dweb-client%2F1.0' 由于此请求失败

如果你能给我提供解决方案,那将非常有帮助 尝试的解决方案: java.net.URLDecoder.decode('/payu/web-response/17703721?appVersion=null&clientId=web-client/1.0', 'UTF-8')

但没有运气

【问题讨论】:

    标签: decode karate


    【解决方案1】:

    空手道做对了。您可以使用这个 3 线空手道测试来亲眼看看:

    * url 'https://httpbin.org/anything'
    * form field foo = 'one/two?three=four'
    * method post
    

    您可以看到“原始”请求是:

    1 > POST https://httpbin.org/anything
    1 > Content-Type: application/x-www-form-urlencoded
    1 > Content-Length: 28
    1 > Host: httpbin.org
    1 > Connection: Keep-Alive
    1 > User-Agent: Apache-HttpClient/4.5.13 (Java/11.0.11)
    1 > Accept-Encoding: gzip,deflate
    foo=one%2Ftwo%3Fthree%3Dfour
    

    但在响应中,您可以看到服务器正确处理了它:

    1 < 200
    1 < Date: Wed, 06 Oct 2021 12:06:10 GMT
    1 < Content-Type: application/json
    1 < Content-Length: 513
    1 < Connection: keep-alive
    1 < Server: gunicorn/19.9.0
    1 < Access-Control-Allow-Origin: *
    1 < Access-Control-Allow-Credentials: true
    {
      "args": {}, 
      "data": "", 
      "files": {}, 
      "form": {
        "foo": "one/two?three=four"
      }, 
      "headers": {
        "Accept-Encoding": "gzip,deflate", 
        "Content-Length": "28", 
        "Content-Type": "application/x-www-form-urlencoded", 
        "Host": "httpbin.org", 
        "User-Agent": "Apache-HttpClient/4.5.13 (Java/11.0.11)", 
        "X-Amzn-Trace-Id": "Root=1-615d9132-260dcbf96f57a6992b6273dc"
      }, 
      "json": null, 
      "method": "POST", 
      "origin": "122.179.54.225", 
      "url": "https://httpbin.org/anything"
    }
    

    查看响应中名为 form 的 JSON 字段。

    我认为您应该做一些研究,或与您的“服务器”团队交谈。谁知道呢,也许空手道已经为你找到了一个错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-09
      • 1970-01-01
      相关资源
      最近更新 更多