首页 > 解决方案 > 空手道 api 测试正在将 @ 转换为 %40,同时拨打电话

问题描述

我已经使用空手道框架编写了一个 api 测试。在进行邮寄呼叫时,它将电子邮件字段的值从 TEST@ABC.COM 转换为 TEST%40ABC.COM。

这是日志中的几行

1 > Content-Type: application/x-www-form-urlencoded; charset=UTF-8
1 > User-Agent: Apache-HttpClient/4.5.5 (Java/1.8.0_221)
email=TEST%40ABC.COM&checkDigit=&brandName=

标签: karate

解决方案


根据 HTTP 规范,这是正确的:https ://stackoverflow.com/a/53638335/143475

你可以自己看看,试试这个:

* url 'http://httpbin.org'
* path 'anything'
* form field username = 'john@smith.com'
* form field password = 'secret'
* method post

结果:

1 > Accept-Encoding: gzip,deflate
1 > Connection: Keep-Alive
1 > Content-Length: 41
1 > Content-Type: application/x-www-form-urlencoded; charset=UTF-8
1 > Host: httpbin.org
1 > User-Agent: Apache-HttpClient/4.5.12 (Java/1.8.0_231)
username=john%40smith.com&password=secret

但是当您看到响应时,您可以看到服务器正确处理了它,查看formJSON 中的:

1 < 200
1 < Access-Control-Allow-Credentials: true
1 < Access-Control-Allow-Origin: *
1 < Connection: keep-alive
1 < Content-Length: 555
1 < Content-Type: application/json
1 < Date: Tue, 07 Apr 2020 13:11:58 GMT
1 < Server: gunicorn/19.9.0
{
  "args": {}, 
  "data": "", 
  "files": {}, 
  "form": {
    "password": "secret", 
    "username": "john@smith.com"
  }, 
  "headers": {
    "Accept-Encoding": "gzip,deflate", 
    "Content-Length": "41", 
    "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", 
    "Host": "httpbin.org", 
    "User-Agent": "Apache-HttpClient/4.5.12 (Java/1.8.0_231)", 
    "X-Amzn-Trace-Id": "Root=1-5e8c7c1e-affe121cae9f4b20399b0884"
  }, 
  "json": null, 
  "method": "POST", 
  "origin": "49.206.10.30", 
  "url": "http://httpbin.org/anything"
}

推荐阅读