Error with a function to request URLS

Hello.
I'm trying to create a function to make GET and POST requests, but I'm having difficulties. I can't find the error.
I would be immensely grateful for the help.
Taking advantage, wouldn't there be an easier way to add headers to a request, without having to create three different objects

#pragma plugin nvgt_curl
string file_get_contents(string url, string path="/", bool post=false, string userAgent="Mozilla/5.0 (Windows NT 6.1; WOW64; rv:7.0.1) Gecko/20100101 Firefox/7.0.12011-10-16 20:23:00"){
http_request request((!post? HTTP_GET: HTTP_POST), path);
http_response response;
https_client client(url);
request["User-Agent"] = userAgent;
client.send_request(request);
datastream@ ds = client.receive_response(response);
return ds.read();
}

void main() {
alert("test", file_get_contents("samtupy.com"));
}

Hi,

A high level http class, similar but better than the old curl internet_request class, will be provided in the near future that will resolve all these issues.

I'll post here when that is done.

1 Like

Hi,

The latest commit to the NVGT repository introduces the first version of this aforementioned class.

It is only slightly documented and there isn't an official release of NVGT that includes it yet, but the vast bulk of the work has been done and the class is accessible if you are willing to build NVGT from source, or else will be included in the next public release.

The class allows retrieval of progress percentage, sending/retrieving headers, asynchronous requests, user agent/retry delay configuration etc.

Hope it solves the problems people were having with previous systems!

1 Like