Simple POST request is not working in Karate API, same will work fine in POSTMAN, please suggest anything wrong in 'request'

 ̄綄美尐妖づ 提交于 2021-02-05 08:33:07

问题


Simple POST method is not working in Karate API, which works fine in POSTMAN, getting error as below

ERROR com.intuit.karate - java.net.ConnectException: Connection refused: connect, http call failed after 1101 milliseconds for URL: https://api.stripe.com/v1/customers

It works fine in POSTMAN and browser URL: https://api.stripe.com/v1/customers

I tried with karate-apache / karate-jersey

Feature: Pharmacies Get Default City Code

  Background:
    * url pharmaciesUrl

  @GetPharmaciesByDefaultCity
  Scenario: Create New Customers
    Given url pharmaciesUrl
    And header Content-Type = 'application/x-www-form-urlencoded'
    And header Authorization = 'Bearer sk_test_Y566a568oL0lbYwRurOvJ4g6'
    Then request {"email": "test1@test.com", "name": "vivek", "description": "Test"}
    When method POST
    Then status 200
    And match response == {id: '#notnull', name: 'vivek'}

Expected: It should create customer with post request which I am passing with status code 200

Actual: Getting below error

09:25:07.278 [main] ERROR com.intuit.karate - java.net.ConnectException: Connection refused: connect, http call failed after 1101 milliseconds for URL: https://api.stripe.com/v1/customers
09:25:07.279 [main] ERROR com.intuit.karate - http request failed: 
java.net.ConnectException: Connection refused: connect
pharmacies.feature:12 -`enter code here`
java.net.ConnectException: Connection refused: connect

回答1:


You haven't read the documentation and you did not realize this is an HTML form submit. The Content-Type should have given you a hint. Here is your solution:

Given url 'https://api.stripe.com/v1/customers'
And header Authorization = 'Bearer sk_test_Y566a568oL0lbYwRurOvJ4g6'
And form field email = 'test1@test.com'
And form field name = 'vivek'
And form field description = 'Test'
When method post
Then status 200


来源:https://stackoverflow.com/questions/57321899/simple-post-request-is-not-working-in-karate-api-same-will-work-fine-in-postman

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!