Hello, I'm trying to write a little script that ******s for some keywords, and returns the names and urls of the first 10 pages found.
PHP Code:
#include <a_samp>
#include <a_http>
forward OnHTTPResponse(index, response_code, data[]);
forward SendHTTPGet(index, url[]);
main()
{
}
public OnRconCommand(cmd[])
{
if(!strcmp(cmd, "http"))
{
SendHTTPGet(42, "www.******.com/search?q=hello+world");
}
return 1;
}
public OnHTTPResponse(index, response_code, data[])
{
printf("OnHTTPResponse(%d, %d)", index, response_code);
switch(response_code)
{
case 200..299: // OK
{
new text[1028];
format(text, 1028, "%s", data);
printf("Data: ");
printf(data);
}
case 300..399: // Redirect
{
new url[512];
new text[1028];
format(text, 1028, "%s", data);
new start_idx = strfind(text, "http://", true, 0) + 7;
new end_idx = strfind(text, "\"", true, start_idx);
strmid(url, text, start_idx, end_idx);
printf("Redirecting...");
SetTimerEx("SendHTTPGet", 500, false, "is", index, url);
}
}
}
public SendHTTPGet(index, url[])
{
printf("Sent request to %s", url);
HTTP(index, HTTP_GET, url, "", "OnHTTPResponse");
}
Then OnHTTPResponse is not being called again.