空手道DSL框架是否具有以URL编码格式传递POST请求的功能? [英] Does Karate DSL Framework have the capability to pass a POST Request as a url encoded format?

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

问题描述

只能使用编码格式通过OAuth 2.0访问我项目中的某些API.我能够使用POSTMAN手动提交POST,因为它具有x-www-form-urlencoded功能来发送请求(附有图像).作为一种解决方法,我创建了一个Java函数来将json主体转换为编码的URI并作为变量传递.但是,运行它时,我收到"URL的HTTP调用失败"的信息.我想知道空手道是否有自己的库来将json转换为Encoded 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:URL 263毫秒后http调用失败:

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框架是否具有以URL编码格式传递POST请求的功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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