C
C#9mo ago
Squirtle

❔ Need help with api call

i need help with an api call
39 Replies
Thinker
Thinker9mo ago
Show your code
Buddy
Buddy9mo ago
$code
MODiX
MODiX9mo ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat If your code is too long, post it to: https://paste.mod.gg/
Thinker
Thinker9mo ago
When I'm running it myself I'm getting a 406 (GZIP encoding must be accepted) response so... might be that?
Squirtle
Squirtle9mo ago
BlazeBin - odfvuslcwlnx
A tool for sharing your source code with the world!
Squirtle
Squirtle9mo ago
BlazeBin - fxxibysrpqda
A tool for sharing your source code with the world!
Squirtle
Squirtle9mo ago
my code so far
cap5lut
cap5lut9mo ago
what exactly is null?
Squirtle
Squirtle9mo ago
historicaldata returns null
cap5lut
cap5lut9mo ago
thats blazor right?
Squirtle
Squirtle9mo ago
yeah
Thinker
Thinker9mo ago
not related to the problem but you should probably use an ILogger instead of Console.WriteLine
cap5lut
cap5lut9mo ago
never touched blazor, but from online examples it looks like u have to the base's OnInitializedAsync(). so sneak in an await base.OnInitializedAsync(); after line 53 where u set the field i guess it would trigger a new render of the component
Squirtle
Squirtle9mo ago
BlazeBin - mlmhfobnmpok
A tool for sharing your source code with the world!
Squirtle
Squirtle9mo ago
my code now still doesnt work
cap5lut
cap5lut9mo ago
and u get the correct json response?
Squirtle
Squirtle9mo ago
dont think the json result is correct this is the result : " jsonResult "\u001f�\b\0\0\0\0\0\0\u0003=�MK�@\f����\u000e3�|���^�=xXJ)�\v�ʶ\nR��M�Kx¼/O�\u0015��r��=\u0001y��\a�;�\u0011\u001bE�d���Qm��S�F�\bw\a�����e�yټl^Vo��2M�s?���u|��]���x�62e�q��@\vχ�C\u001daC�����\u007f\u000f�_�\u007fX�2�\v�!�DE��my�65�k��Dbr\u001e#���Ed�-{���c��#l�\u0005��k�\u0011%�Q"��Cv\r�"5�D\fEV\nJ��LR��\u001dr��K\%�\u0012&y\vᯰ�\u001aC�\u0014�(\u001a=�⽑���>�f��]$ʬ����~\u0001��b��\u0001\0\0" string "
cap5lut
cap5lut9mo ago
yeah thats some binary data, not valid json, so something is wrong with the request itself what does ur console say, does it throw an exception? or does it reach the "Failed to retrieve data" branch?
Squirtle
Squirtle9mo ago
"blazor.server.js:1 [2023-09-14T10:11:16.427Z] Information: Normalizing '_blazor' to 'https://localhost:44306/_blazor'. blazor.server.js:1 [2023-09-14T10:11:16.446Z] Information: WebSocket connected to wss://localhost:44306/_blazor?id=hi5I3tdzCHvQZ6Xo9YE-pw. browserLink:3299 [Deprecation] Listener added for a synchronous 'DOMNodeInserted' DOM Mutation Event. This event type is deprecated (https://w3c.github.io/uievents/#legacy-event-types) and work is underway to remove it from this browser. Usage of this event listener will cause performance issues today, and represents a risk of future incompatibility. Consider using MutationObserver instead. Dv @ browserLink:3299 DevTools failed to load source map: Could not load content for chrome-extension://bfnaelmomeimhlpmgjnjophhpkkoljpa/content-script/contentScript.js.map: Systemfel: net::ERR_BLOCKED_BY_CLIENT DevTools failed to load source map: Could not load content for chrome-extension://bmnlcjabgnpnenekpadlanbbkooimhnj/browser-polyfill.js.map: Systemfel: net::ERR_BLOCKED_BY_CLIENT" this is my console
cap5lut
cap5lut9mo ago
wait it has to reach the exception
Squirtle
Squirtle9mo ago
the above is my console
cap5lut
cap5lut9mo ago
tbh im not sure where ur logs end up, doesnt seem like its in that console
Squirtle
Squirtle9mo ago
are you available for a call?
cap5lut
cap5lut9mo ago
sorry, nope
Squirtle
Squirtle9mo ago
dam
cap5lut
cap5lut9mo ago
the only other difference i see to online examples is, that u have a private field, while examples use properties, but i doubt its that.
MODiX
MODiX9mo ago
cap5lut
REPL Result: Failure
await new System.Net.Http.HttpClient().GetStringAsync("https://opendata-download-metanalys.smhi.se/api/category/pthbv1g/version/1/geotype/multipoint/from/2022/to/2023/period/monthly/data.json?epsg=4326&ll=16.527,59.382&var=p&var=t")
await new System.Net.Http.HttpClient().GetStringAsync("https://opendata-download-metanalys.smhi.se/api/category/pthbv1g/version/1/geotype/multipoint/from/2022/to/2023/period/monthly/data.json?epsg=4326&ll=16.527,59.382&var=p&var=t")
Exception: HttpRequestException
- Response status code does not indicate success: 406 (GZIP encoding must be accepted).
- Response status code does not indicate success: 406 (GZIP encoding must be accepted).
Compile: 452.083ms | Execution: 1006.063ms | React with ❌ to remove this embed.
cap5lut
cap5lut9mo ago
that seems to be ur problem, its compressed
MODiX
MODiX9mo ago
cap5lut
REPL Result: Success
var handler = new System.Net.Http.HttpClientHandler()
{
AutomaticDecompression = System.Net.DecompressionMethods.GZip
};
await new System.Net.Http.HttpClient(handler)
.GetStringAsync("https://opendata-download-metanalys.smhi.se/api/category/pthbv1g/version/1/geotype/multipoint/from/2022/to/2023/period/monthly/data.json?epsg=4326&ll=16.527,59.382&var=p&var=t")
var handler = new System.Net.Http.HttpClientHandler()
{
AutomaticDecompression = System.Net.DecompressionMethods.GZip
};
await new System.Net.Http.HttpClient(handler)
.GetStringAsync("https://opendata-download-metanalys.smhi.se/api/category/pthbv1g/version/1/geotype/multipoint/from/2022/to/2023/period/monthly/data.json?epsg=4326&ll=16.527,59.382&var=p&var=t")
Result: string
{"dates":["2022-01","2022-02","2022-03","2022-04","2022-05","2022-06","2022-07","2022-08","2022-09","2022-10","2022-11","2022-12","2023-01","2023-02","2023-03","2023-04","2023-05","2023-06","2023-07","2023-08"],"coord_sys_info":{"EPSG":4326,"name":"WGS 84"},"point_values":[{"east":16.527,"north":59.382,"p":[45.0,43.7,0.4,33.0,60.6,36.3,48.2,92.1,24.3,41.3,44.7,34.6,77.1,26.9,57.0,16.4,17.9,21.4,103.2,224.0],"t":[0.1,0.4,2.5,5.2,11.4,17.4,17.8,18.4,11.2,9.3,5.0,-3.1,0.5,-0.1,-0.1,5.4,12.1,17.9,16.6,16.3]}]}
{"dates":["2022-01","2022-02","2022-03","2022-04","2022-05","2022-06","2022-07","2022-08","2022-09","2022-10","2022-11","2022-12","2023-01","2023-02","2023-03","2023-04","2023-05","2023-06","2023-07","2023-08"],"coord_sys_info":{"EPSG":4326,"name":"WGS 84"},"point_values":[{"east":16.527,"north":59.382,"p":[45.0,43.7,0.4,33.0,60.6,36.3,48.2,92.1,24.3,41.3,44.7,34.6,77.1,26.9,57.0,16.4,17.9,21.4,103.2,224.0],"t":[0.1,0.4,2.5,5.2,11.4,17.4,17.8,18.4,11.2,9.3,5.0,-3.1,0.5,-0.1,-0.1,5.4,12.1,17.9,16.6,16.3]}]}
Compile: 508.828ms | Execution: 1336.028ms | React with ❌ to remove this embed.
cap5lut
cap5lut9mo ago
yeah u need to set up automatic decompression
Squirtle
Squirtle9mo ago
yeah it worked ❤️ thanksss how did u know that i mean how did u get to the result
cap5lut
cap5lut9mo ago
well, we saw already that its binary data. then from the first eval the error message:
Response status code does not indicate success: 406 (GZIP encoding must be accepted).
and then i quickly googled how to use httpclient with gzip decompression ;p
Pobiega
Pobiega9mo ago
I mean, Thinker said that in the first messages of this thread https://discord.com/channels/143867839282020352/1151809075458347038/1151813882185256961
MODiX
MODiX9mo ago
Thinker
When I'm running it myself I'm getting a 406 (GZIP encoding must be accepted) response so... might be that?
Quoted by
<@105026391237480448> from #Need help with api call (click here)
React with ❌ to remove this embed.
cap5lut
cap5lut9mo ago
oh i totally missed that message >.<
Squirtle
Squirtle9mo ago
"well, we saw already that its binary data. then from the first eval the error message: Response status code does not indicate success: 406 (GZIP encoding must be accepted). and then i quickly googled how to use httpclient with gzip decompression ;p" where can i see messages like this never saw it
cap5lut
cap5lut9mo ago
binary data the eval with the error message
Accord
Accord9mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.