Does Karate DSL Framework have the capability to pass a POST Request as a url encoded format?
Asked Answered
I

2

1

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.

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 call failed after 263 milliseconds for URL: http://location.ver02.geicenter.com/uaa/oauth/tokenenter image description here

Ilario answered 20/9, 2017 at 21:25 Comment(0)
I
1

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 
Ilario answered 26/9, 2017 at 18:18 Comment(1)
There is a beta version 0.6.0.2 available that fixes one of the SSL problems. So you don't need a certificate and just having "* configure ssl = true" should be sufficient. Would be great if you can verify this works for you.Bobbi
B
1

Yes. Please refer to the documentation for form field. There is also an OAuth 2 example in the demos, look for it.

Also see: https://mcmap.net/q/1770288/-how-to-setup-oauth-1-0-authentication-with-karate-for-twitter-duplicate

Bobbi answered 21/9, 2017 at 0:47 Comment(0)
I
1

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 
Ilario answered 26/9, 2017 at 18:18 Comment(1)
There is a beta version 0.6.0.2 available that fixes one of the SSL problems. So you don't need a certificate and just having "* configure ssl = true" should be sufficient. Would be great if you can verify this works for you.Bobbi

© 2022 - 2024 — McMap. All rights reserved.