How to resolve error 415 Unsupported Media Type when Content-Type is correctly set

后端 未结 3 1888
慢半拍i
慢半拍i 2021-01-15 19:10

I have a simple POST request that requires a json Content-Type header and a body like

{
   oneNbr: \"2016004444\",
   twoCode: \"@@@\",
   threeNbr: \"STD PA         


        
相关标签:
3条回答
  • 2021-01-15 19:34

    We did some debugging and found that Karate automatically appends 'charset=UTF-8' to the Content-Type header. The API does not expect charset.

    Found the following post and that solved the problem:

    How can I send just 'application/json' as the content-type header with Karate?

    Posting this to help others in future.

    0 讨论(0)
  • 2021-01-15 19:55

    It's simple. Try to use this in your background.

    * def charset = null
    
    0 讨论(0)
  • 2021-01-15 19:58

    Try adding a * header Accept = 'application/json' header. The one difference between Karate and Postman is that Postman tries to be smart and auto-adds an Accept header - whereas Karate does not.

    0 讨论(0)
提交回复
热议问题