Karate: Content-Type not being able to pass due to "-"

Created on 15 Apr 2019  路  4Comments  路  Source: intuit/karate

Content-Type not being able to pass due to "-" in request header.

This is occurring from headers.js file and when function () is being called.

-unknown-:6 - javascript evaluation failed: read('classpath:headers.js'), javascript evaluation failed: function()
{return{requesting_app_name: 'ABC', Content-Type = 'application/json', app_key: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
}
}, :2:43 Expected : but found -
{return{requesting_app_name: 'ABC', Content-Type = 'application/json', app_key: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
^ in at line number 2 at column number 43

Version 0.9.0

It works perfectly if i pass this in * configure headers = { TrackingId: 'SomeValue', Token: 'AnotherValue' }.

Bascially the function method doesn't work if there is a "-" in Content-Type

Most helpful comment

That did that trick, thanks for fresh eyes.

All 4 comments

@sadiqkassamali : If i understand your query correctly, you are unable to send 'Content-Type' in headers. So please use Content-Type in string quotes since it has a special character in it

refer -> https://github.com/intuit/karate#headers.

Try with

function()
{return{'requesting_app_name': 'ABC', 'Content-Type' : 'application/json', 'app_key': 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
}

Note: You don't need to mention header { 'Content-Type': 'application/json' } since karate automatically appends it to your request headers

No luck, now it's expecting a comma

-unknown-:6 - javascript evaluation failed: read(classpath:headers.js), :1:14 Expected , but found :
read(classpath:headers.js)
^ in at line number 1 at column number 14

function()
{return{'requesting_app_name': 'ABC', 'Content-Type' = 'application/json', 'app_key': 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
}
}

You are using 'Content-Type' = 'application/json', try 'Content-Type' : 'application/json'. If it doesn't work, please attach your sample project here.

That did that trick, thanks for fresh eyes.

Was this page helpful?
0 / 5 - 0 ratings