16.03.2016, 13:24
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.
I just started with this code:
But I get
Then OnHTTPResponse is not being called again.
Please help
I just started with this code:
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");
}
Code:
[14:26:32] Filterscript 'webBrowser.amx' loaded. [14:26:32] Number of vehicle models: 0 Console input: http [14:26:36] Sent request to www.******.com/search?q=hello+world [14:26:36] OnHTTPResponse(42, 302) [14:26:36] Redirecting... [14:26:36] Sent request to www.******.it/search?q=hello+world&gws_rd=cr&ei=N17pVuXHCsHOOPqUt5AB
Please help
![Smiley](images/smilies/smile.png)