Nodir Musaev

05/30/2023, 7:59 AM
Hello Can someone help me with this issue? Text from the issue:
By default the .postMapping method creates a stub using an URLRequest with a default Content-Type “application/x-www-form-urlencoded”, which is incorrect. The value of this header should be “application/json” since the body is actually JSON.
I am having an issue where a security equipment between my client code and the mock server blocks all stub creations because of the incorrect value of this HTTP Header.
I tested that the correct value “application/json” works as intended.
Do you think it would be possible to use the correct value for all stub creations please ?
Thank you for your help.
(If you need, I can provide a PR)
We are facing same problem. In response data we printed result:
Copy code
(lldb) po String(data: data!, encoding: .utf8)
▿ Optional<String>
 - some : "{\n \"errors\" : [ {\n  \"code\" : 10,\n  \"source\" : { },\n  \"title\" : \"Error parsing JSON\",\n  \"detail\" : \"Unexpected character (\'%\' (code 37)): expected a valid value (JSON String, Number, Array, Object or token \'null\', \'true\' or \'false\')\\n at [Source: (String)\\\"... more response data code here
version: 3.0.0 client: iOS

Oleg Nenashev

05/30/2023, 8:41 AM
IIUC the issue, a patch of is needed

Nodir Musaev

05/30/2023, 8:56 AM
Yes. We added:
Copy code
urlRequest.setValue("application/json", forHTTPHeaderField: "Content-Type")
And it works