空手道 DSL 框架是否能够将 POST 请求作为 url 编码格式传递? [英] Does Karate DSL Framework have the capability to pass a POST Request as a url encoded format?

查看:20
本文介绍了空手道 DSL 框架是否能够将 POST 请求作为 url 编码格式传递?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我项目中的某些 API 只能使用编码格式通过 OAuth 2.0 访问.我可以使用 POSTMAN 手动提交 POST,因为它具有 x-www-form-urlencoded 功能来发送请求(附上图片).作为一种解决方法,我创建了一个 java 函数来将我的 json 主体转换为编码的 URI 并作为变量传递.但是,我在运行它时收到URL 的 http 调用失败".我想知道空手道是否有自己的库来将 json 转换为编码的 URI.

Certain APIs in my project can only be accessed via OAuth 2.0 using an encoded format. I am able to manually submit a POST using POSTMAN as it has the x-www-form-urlencoded feature to send the request (image attached). As a workaround, I created a java function to convert my json body to an encoded URI and passed as a variable. However, I am getting a "http call failed for URL" when running it. I was wondering if Karate has its own library to convert json to Encoded URIs.

场景:JSON 到 POST 正文上的编码 URI

Scenario: Json to Encoded URI on POST body

* def JavaDemo = Java.type('com.ge.health.gam.service.servicerequest.testsuite.CustomJavaClass')
* def encodedURI = JavaDemo.jsonToURI()
* print encodedURI

Given url 'http://location.ver02.geicenter.com/uaa/oauth/token'
And request encodedURI
When method post
Then status 200

com.intuit.karate.exception.KarateException:http 调用在 URL 263 毫秒后失败:

com.intuit.karate.exception.KarateException: http call failed after 263 milliseconds for URL:

推荐答案

根据 Peter Thomas 的建议,我发现以下内容可以通过 Oath 2.0 提交请求.就我而言,我还必须安装所需的证书才能收到有效的响应.你也必须考虑到这一点.

As suggested by Peter Thomas, I found the below to be able to submit requests via Oath 2.0. In my case, I also had to install a required certificate in order to receive a valid response. you also have to take that into consideration.

Given path 'uaa', 'oauth', 'token'
And form field key = 'value'
And form field key = 'value'
And form field key = 'value'
And form field key = 'value'
When method post
Then status 200 

这篇关于空手道 DSL 框架是否能够将 POST 请求作为 url 编码格式传递?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆