+ Start a Discussion
Gautam_KasukhelaGautam_Kasukhela 

Illegal character(s) in message header

Hello All,
      I am facing a Callout exception which says " Illegal character(s) in message header value: 
{"HEADER": {"APPLICATION-ID": "APP-0000010120", "CUST-ID": "P/001N000000p35DTIAY","REQUEST-TYPE": "REQUEST","REQUEST-TIME":"08092016 16:15:11"},"REQUEST": {"03":"PERSONAL LOAN","04":"421000","07":"DIRECT","11":"QA/UAT","21": {"01":"A B C"},"22":"MALE","27":"02091992","29":[ {"01":"RESIDENCE","03":"543543544","04":"Bihupuria","06":"Assam","05":"435435"}],"30":{"01":"YHGPS7560W"},"31":[{"01": "MOBILE","02":"9664561852"}],"36":"456465465464"}}
"

I have set the header if the request as follows:-
httpReq.setHeader('inputJson_',jsonRequestBody); 
In the 'jsonRequestBody', I have set the content that is show above in curly braces. 

Strange thing is that, if I use the same header value through a REST client (Postman), it works fine. From within Apex, I get the above mentioned issue. Can anyone let me know what is wrong here?

Regards,
Gautam.
Best Answer chosen by Gautam_Kasukhela
Gautam_KasukhelaGautam_Kasukhela
The issue was with a newline character that I had in my code while forming the request. Removed the newline (\n) character from the Apex code and the request went through fine.

Regards,
Gautam.

All Answers

karthikeyan perumalkarthikeyan perumal
Hello Gautam, 

Issue might be ( / ) of this char. try to omit this char from your JSON 

Thanks
Karthik



 
Gautam_KasukhelaGautam_Kasukhela
Hello Karthikeyan,
            I have tried by removing '/' and ':' (colon) but it did not help. It still shows the same error.

Regards,
Gautam.
karthikeyan perumalkarthikeyan perumal
Hello Gautam, 

Before sending request encode you JSON string using like this.

String myBase64String = EncodingUtil.base64Encode(Blob.valueof(myString));

its may help you. 

Thanks
karthik
 
Gautam_KasukhelaGautam_Kasukhela
The issue was with a newline character that I had in my code while forming the request. Removed the newline (\n) character from the Apex code and the request went through fine.

Regards,
Gautam.
This was selected as the best answer