I'm trying to write a program that download some things from a remote server,
#include <iostream>
#include <string>
#include <Windows.h>
#include <WinInet.h>
#pragma comment(lib,"wininet.lib")
using namespace std;
string Get(){
DWORD size = 0;
DWORD wrt;
string msg = "";
HINTERNET io=InternetOpen("Downloader",INTERNET_OPEN_TYPE_DIRECT,NULL,NULL,0);
HINTERNET ic=InternetConnect(io,"192.168.1.15",8080,NULL,NULL,INTERNET_SERVICE_HTTP,0,0);
HINTERNET hreq=HttpOpenRequest(ic,NULL,"/cgi-bin/cmd.py","HTTP/1.0",NULL,NULL,0,0);
HttpSendRequest(hreq,NULL,0,NULL,0);
InternetQueryDataAvailable(hreq,&size,0,0);
char* buffer = new char[size+1];
memset(buffer,0,size+1);
InternetReadFile(hreq,buffer,size,&wrt);
msg += buffer;
free(buffer);
InternetCloseHandle(io);
InternetCloseHandle(ic);
InternetCloseHandle(hreq);
return msg;
}
int main(){
while(TRUE){
string msg=Get();
if(msg.length()>1){
cout<<msg<<endl;
}
Sleep(2000);
}
return 0;
}
In the other side (on server ) I run a python CGI script , to send the text. The problem is that the program send the GET request just one time, even if there is a loop and the msg.length() is equal to 0 , in the other side I can see that I just recieved one GET request . Can someone solve my problem, or any idea ....