Quantcast
Channel: Forums - Recent Threads
Viewing all articles
Browse latest Browse all 143529

Unable to send post request

$
0
0

This is my code:

var
Client: HttpClient;
Headers: HttpHeaders;
Content: HttpContent;
Url: Text;
MyContent: Text;
TempBlob: Record TempBlob;
APIResult: Boolean;APIOutput: Text;
AuthText: Text;
begin
Client.DefaultRequestHeaders.Add('Accept', 'application/json');
Content.Clear();
Content.WriteFrom(MyContent);
Headers.Clear();
AuthText := StrSubstNo('username:password');
TempBlob.WriteAsText(AuthText, TextEncoding::Windows);
Headers.Add('Authorization', StrSubstNo('Basic %1', TempBlob.ToBase64String()));
Headers.Add('Content-Type', 'application/json');
Content.GetHeaders(Headers);
if not Client.Post(Url, Content, ResponseMessage) then begin
Error('The call to the web service failed.');
end;
Headers := ResponseMessage.Headers();
ResponseMessage.Content().ReadAs(APIOutput);
Message(APIOutput);
EXIT(ResponseMessage.IsSuccessStatusCode());
At the Headers.Add('Content-Type', 'application/json'); get the following error:
Element 'Headers' is not a member of 'Content'
Think this is caused by the previous line, been unable to find anywhere online where this error has occurred previously. Been struggling with this for days, have tried without the authorization but still the error the same.

Viewing all articles
Browse latest Browse all 143529

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>