I am trying to start a post request to my web service. But unfortunately it doesn't quite work yet.
procedure sendPostRequest()
var
client: HttpClient;
content: HttpContent;
headers: HttpHeaders;
response: HttpResponseMessage;
request: HttpRequestMessage;
MessagingServiceSetup: Record "Messaging Service Setup WMR";
IsSuccessful: Boolean;
JsonText: Text;
ResponseStream: InStream;
TempBlob: Codeunit "Temp Blob";
ResponseJson: JsonObject;
jwt: text;
begin
MessagingServiceSetup.Get();
request.GetHeaders(headers);
headers.Add('Accept', 'application/json');
headers.Add('user', 'Dynamics 365');
request.SetRequestUri(MessagingServiceSetup."Service URL");
request.Method('POST');
JsonText := BuildAuthReqContent(MessagingServiceSetup.Username, MessagingServiceSetup.Password);
content.WriteFrom(JsonText);
request.Content(content);
IsSuccessful := client.Send(request, response);
if not IsSuccessful then
Error('Authentication failed!');
if not response.IsSuccessStatusCode then begin
//Fehlerhandling
exit;
end;
clear(TempBlob);
TempBlob.CreateInStream(ResponseStream);
response.Content.ReadAs(ResponseStream);
ResponseJson.ReadFrom(ResponseStream);
GetPropertyFromJsonObject(ResponseJson, 'jwt', jwt);
if confirm(jwt) then;
end;
local procedure GetPropertyFromJsonObject(var JsonObject: JsonObject; PropertyName: Text; var PropertyValue: Text)
var
ValueToken: JsonToken;
Value: JsonValue;
begin
if JsonObject.Get(PropertyName, ValueToken) then
if ValueToken.IsValue then begin
Value := ValueToken.AsValue();
If not (Value.IsNull or Value.IsUndefined) then
PropertyValue := Value.AsText();
end;
end;
procedure SetURLsToDefault(var MessagingServiceSetup: Record "Messaging Service Setup WMR")
begin
MessagingServiceSetup."Service URL" := '';
end;
local procedure BuildAuthReqContent(Username: Text[50]; Password: Text[250]) ContentText: Text
var
ContentJson: JsonObject;
begin
ContentJson.Add('username', Username);
ContentJson.Add('password', Password);
ContentJson.WriteTo(ContentText);
end;
when I debug I get the error code 415 and I don't know why it comes. Everything seems to be good with the request but there are problems with the response.

if I send the same request through Postman, everything works fine. Can anyone tell me what I am doing wrong? The goal is to start a post request to my web service and to save a jwt token received in the Json in the field MessagingServiceSetup.token