» »

Wininet problem

Wininet problem

*ziga* ::

Mogoce kdo ve kaj je pri tej kodi narobe? Imam cca 10 requestov in ce je 1 request SSL potem program na nekaterih racunalnikih crashne(na mojih + vmware dela ok)

char Buffer[1024];
DWORD dwRead;
string data;

string Request(string method, string host, string file, string headers, string post, bool debug, bool SSL){
HINTERNET hSession, hDownload, hRequest;
DWORD flag;
DWORD port;


data.empty();


//SSL or not + flag :)
if(SSL){
port = INTERNET_DEFAULT_HTTPS_PORT;
flag = INTERNET_FLAG_SECURE; // FLAG_SECURE
} else {
port = INTERNET_DEFAULT_HTTP_PORT;
flag = INTERNET_FLAG_RELOAD; //FLAG_RELOAD
}
  
char * postdata;
postdata = new char [post.size()+1];
strcpy (postdata, post.c_str());
char * headersdata;
headersdata = new char [headers.size()+1];
strcpy (headersdata, headers.c_str());       


 
//Actual request
hSession = InternetOpen("Mozilla/5.0 (Windows; U; Windows NT 6.1; sl; rv:1.9.2.11) Gecko/20101012 Firefox/3.6.11", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
if(hSession){
hDownload = InternetConnect(hSession, host.c_str(), port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
if(hDownload){
hRequest = HttpOpenRequest(hDownload, method.c_str(), file.c_str(), "HTTP/1.1", NULL, NULL, flag, 0);
if(hRequest){
if(strlen(headersdata) && strlen(postdata)){
HttpSendRequest(hRequest, headersdata, strlen(headersdata), postdata, strlen(postdata));
} else {
HttpSendRequest(hRequest, NULL, 0, NULL, 0);      
}
}
}
}
//Writing HTML response in data buffer
while(InternetReadFile(hRequest, Buffer, sizeof(Buffer), &dwRead))
  {
    if (dwRead == 0)
	{
      break;
	}
	Buffer[dwRead] = 0;
	data += Buffer;
  }


//Debug :)
if(debug){
ofstream dbgfile;
dbgfile.open ("debug.html");
dbgfile << data;
dbgfile.close();        
}

//Close handles
InternetCloseHandle(hSession);
InternetCloseHandle(hDownload);
InternetCloseHandle(hRequest);

return data;
}


Vredno ogleda ...

TemaSporočilaOglediZadnje sporočilo
TemaSporočilaOglediZadnje sporočilo
»

Davčne blagajne (strani: 1 2 3 424 25 26 27 )

Oddelek: Programiranje
1344332564 (72567) Macketina
»

[JAVA] HTTPS client

Oddelek: Programiranje
173176 (1906) peterv6i
»

[C++] charset-a

Oddelek: Programiranje
7898 (755) SasoS
»

[baze] Povezava do slike ali BLOB?

Oddelek: Programiranje
101658 (1455) BlueRunner
»

[C#] Prosim pomagajte! Potrebujem program, ki bi pobiral podatke iz ene strani

Oddelek: Programiranje
212746 (2356) David1994

Več podobnih tem