I am trying to make a connection to external WS and I get an error related to - Misused Header name.
I believe this is due to "Content-Type" and may be the syntax is incorrect.???
I have tried to access the same WS via Postman and I was able to get a success message.…
Any Ideas what is wrong here?
TIA
//Header
header.Clear();
header.Add('Content-type', 'application/json');
header := myclient.DefaultRequestHeaders();
header.Add('username', 'USERNAME');
header.Add('password', 'PASSWORD');
header.Add('UserAgent', 'Apache-HttpClient/4.1.1 (java 1.5)');
header.Add('Connection', 'KeepAlive');
//CONTENT
content.Clear();
content.GetHeaders(header);
content.WriteFrom(_JSonText); // Created a Json Object Request and converted to text.
request.Content := content;
request.Content.GetHeaders(header);
request.GetHeaders(header);
request.SetRequestUri(ReqURL);
request.Method := 'POST';
myclient.Post(ReqURL, content, response);
Message(_JSonText);
response.Content().ReadAs(http_Response);
Message(http_Response);
IF response.HttpStatusCode = 200 then
Message('Success')
ELSE
Message('Error');
0
Answers
It's better to remove the 'Content-Type' (T in uppercase) before adding the value, like:
By calling
You don't use the request variable at all, you must use:
And separate the content header and the request header, 'Content-Type' is part of the content header, and the username, password, etc are part of the request header.
Regards.