HttpResponseMessage.Content.ReadAs(InStream) fails if read multible times
1. Describe the bug HttpResponseMessage.Content.ReadAs(InStream) returns an emtpy stream for second and following times. This does only happen if we concat commands. if we store the HttpContent in an Variable everything works fine.
2. To Reproduce Copy and run this code:
pageextension 50100 CustomerListExt extends "Customer List"
{
trigger OnOpenPage()
var
response: HttpResponseMessage;
handler: codeunit Handler;
jobj: JsonObject;
str: InStream;
content: HttpContent;
begin
// BAD CODE
handler.DoRequest();
handler.GetResponse().Content.ReadAs(str);
jobj.ReadFrom(str);
handler.GetResponse().Content.ReadAs(str);
jobj.ReadFrom(str); // <-- this will fail
// GOOD CODE
handler.DoRequest();
content := handler.GetResponse().Content;
content.ReadAs(str);
jobj.ReadFrom(str);
content := handler.GetResponse().Content;
content.ReadAs(str);
jobj.ReadFrom(str);
end;
}
codeunit 50100 Handler
{
var
Global_Response: HttpResponseMessage;
procedure DoRequest()
var
client: HttpClient;
response: HttpResponseMessage;
begin
client.Get('https://dummyjson.com/test', response);
Global_Response := response
end;
procedure GetResponse(): HttpResponseMessage
begin
exit(Global_Response);
end;
}
Note: Because the developers need to copy and paste the code snippet, including a code snippet as a media file (i.e. .gif) is not sufficient.
3. Expected behavior We expect that we can read the content as stream multible times.
4. Actual behavior Error:
If requesting support, please provide the following details to help troubleshooting:
The data does not represent a valid JSON token.
Page Customers has to close.
Internal session ID: fd433d3f-40df-4fc4-afbc-dca4c70d52f4
Application Insights session ID: b57da906-90ab-42ec-a3d3-95a0a61786b4
Client activity id: 1f4742c3-12d8-7d3a-0d83-49f7a56a0c87
Time stamp on error: 2023-09-19T14:14:24.6052521Z
AL call stack: CustomerListExt(PageExtension 50100).OnOpenPage(Trigger) line 12 - HttpRequestContent by Default publisher
5. Versions:
-
AL Language: v13.0.864697
-
Visual Studio Code: 1.82.1
-
Business Central:
- DE Business Central 22.5 (Platform 22.0.60139.0 + Application 22.5.59966.60187)
- DE Business Central 23.0 (Plattform 23.0.12299.0 + Application 23.0.12034.12313)
-
List of Visual Studio Code extensions that you have installed: ms-dynamics-smb.al
Final Checklist
Please remember to do the following:
-
[x] Search the issue repository to ensure you are reporting a new issue
-
[x] Reproduce the issue after disabling all extensions except the AL Language extension
-
[x] Simplify your code around the issue to better isolate the problem