can't seem to use fetch api

main
Brett 2025-04-11 16:27:55 -04:00
parent e2dc35fea9
commit b6fc170399
2 changed files with 6 additions and 5 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.20)
include(cmake/color.cmake)
set(BLT_VERSION 5.3.0)
set(BLT_VERSION 5.3.1)
set(BLT_TARGET BLT)

View File

@ -85,10 +85,11 @@ namespace blt::requests
std::string send_get_request(const std::string& url)
{
#ifdef __EMSCRIPTEN__
auto* str = static_cast<char*>(EM_ASM_PTR(
{ const v = await fetch('$0', { 'credentials': 'omit', 'headers': { 'User-Agent':
'Mozilla/5.0 (X11; Linux x86_64; rv:136.0) Gecko/20100101 Firefox/136.0', 'Accept': '/', 'Accept-Language': 'en-US,en;q=0.5',
'Priority': 'u=4' }, 'method': 'GET', 'mode': 'cors' }); if (!v.ok) { throw v.status; } return stringToNewUTF8(await response.text());
auto* str = static_cast<char*>(EM_ASM_PTR({
var xhr = new XMLHttpRequest();
xhr.open("GET", $0);
xhr.send();
return stringToNewUTF8(xhr.responseText);
}, url.c_str()));
std::string str_obj{str};
free(str);