nejde to dako ono my to vytvori ine teda DEV dokument a ked to otvorim tak mi otvori DEV++ a este ten co my to daval ten script pisal ze to mam dat do meta ci kam
toto my napisal citujem ho
stiahni si dev-c++, do main() vloz volanie tej fcie v cykle, a vloz tam tu fciu samozrejme, na zaciatok potrene includy. potom to vykompiluj a budes mat program exe
Kód:
#define HTTP_USER_AGENT "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20021204"
#define HTTP_TIMEOUT 300
/**
* XS: Sends HTTP request to specified host,
* additional parameters could be set in structure HTTPCLIENT as 4th param.
*
*/
BOOL HTTPRequest(char *Method, char *Hostname, char *Url, HTTPCLIENT HttpClient,
char *Result, int ResultSize) {
char Request[2048];
WSADATA WSAData ;
HOSTENT *Host;
SOCKADDR_IN HostAddr;
SOCKET Sock;
//
// Open connection to HTTP server
//
// Winsock initialisation
if(WSAStartup(MAKEWORD(2,0), &WSAData) !=0) {
printf("HTTPRequest(): Couldn't initialise winsock");
return 0;
}
// Resolve IP adress of mail server
if ((Host = gethostbyname(Hostname)) == NULL) {
printf("Couldn't resolve server address\r\n");
WSACleanup();
return 0;
}
// Copy resolved address and type to HostAddr structure
memset(&HostAddr, 0, sizeof(HostAddr));
memcpy(&(HostAddr.sin_addr), Host->h_addr, Host->h_length);
HostAddr.sin_family = Host->h_addrtype;
HostAddr.sin_port = htons(80);
// Create socket
if ((Sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) == INVALID_SOCKET) {
printf("HTTPRequest(): Couldn't create socket");
WSACleanup();
return 0;
}
// Connect to HTTP server with new socket
if ((connect(Sock, (SOCKADDR*)&HostAddr, sizeof(HostAddr))) == SOCKET_ERROR) {
printf("Couldn't connect to server");
closesocket(Sock);
WSACleanup;
return 0;
}
// Wait for server
sleep(HTTP_TIMEOUT);
// Lets build HTTP request
//if (strcmpi(Method, "POST") == 0) {
if (1) {
sprintf(Request, "%s %s HTTP/1.1\r\n\
Host: %s\r\n\
User-Agent: %s\r\n\
Referer: %s\r\n\
Accept: text/xml,application/xml,application/xhtml+xml,\
text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,\
image/jpeg,image/gif;q=0.2,text/css,*/*;q=0.1\r\n\
Accept-Language: en-us, en;q=0.50\r\n\
Content-Type: application/x-www-form-urlencoded\r\n\
Content-Length: %i\r\n\
Connection: Close\r\n\r\n%s",
Method, Url, Hostname, HttpClient.UserAgent, HttpClient.Referer,
strlen(HttpClient.Data), HttpClient.Data);
} else {
sprintf(Request, "%s %s HTTP/1.1\r\n\
Host: %s\r\n\
User-Agent: %s\r\n\
Referer: %s\r\n\
Accept: text/xml,application/xml,application/xhtml+xml,\
text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,\
image/jpeg,image/gif;q=0.2,text/css,*/*;q=0.1\r\n\
Accept-Language: en-us, en;q=0.50\r\n\
Connection: Close\r\n\r\n",
Method, Url, Hostname, HttpClient.UserAgent, HttpClient.Referer);
}
// Send HTTP request
send(Sock, Request, strlen(Request), 0);
// Wait for response
sleep(HttpClient.Timeout);
// Get result
recv(Sock, Result, ResultSize - 1, 0);
Result[ResultSize - 1] = '\0';
// Do cleanup and return TRUE
closesocket(Sock);
WSACleanup();
return 1;
}