C++ HTTP Post

Status
Niet open voor verdere reacties.

Louren

Gebruiker
Lid geworden
21 apr 2008
Berichten
21
Hallo allemaal,

Ik heb een probleem met het versturen van een Http Post-request. Ik heb het volgende op internet gevonden:
Code:
#include <Windows.h>
#include <WinINet.h>
#include <string>
#include <iostream>
using namespace std;

int main( int argc, char **argv )
{
	DWORD ptr = 0x1001;
	HINTERNET hi_io = InternetOpen("vc_agent",INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
	HINTERNET hi_ic = InternetConnect(hi_io,"localhost",INTERNET_DEFAULT_HTTP_PORT,NULL,NULL,INTERNET_SERVICE_HTTP,0,ptr);
	HINTERNET hi_hor = HttpOpenRequest(hi_ic,"POST","testpage.asp",NULL,NULL,NULL,INTERNET_FLAG_RELOAD,ptr);
	string data = "text_one=myname";
	BOOL b = HttpSendRequest(hi_hor,NULL,0,(LPVOID)(LPCSTR)data,data.GetLength());
	
	while(1)
	{
		char buffer[100]={0};
		DWORD read=0;
		BOOL r = InternetReadFile(hi_hor,buffer,100,&read);
		if(r && read==0) 
			break;
	}

	InternetCloseHandle(hi_hor);
	InternetCloseHandle(hi_ic);
	InternetCloseHandle(hi_io);

    system("PAUSE");
    return EXIT_SUCCESS;
}

Deze geeft echter een probleem bij het compileren:

Code:
Row 14: cannot convert `data' from type `std::string' to type `const CHAR*' 
[B]en[/B]
Row 14: 'struct std::string' has no member named 'GetLength'

Wie weet wat er fout is aan dit script?
Ik snap dat het probleem komt doordat een verkeerde soort variabele gebruikt word (toch? :rolleyes:).. maar welke variabele moet ik dan wel gebruiken en hoe doe ik dat?

Alvast bedankt! :D
 
Verander

BOOL b = HttpSendRequest(hi_hor,NULL,0,(LPVOID)(LPCSTR)data,data.GetLength());

naar

BOOL b = HttpSendRequest(hi_hor,NULL,0,(LPVOID)(LPCSTR)data.c_str(),data.length());


Werkt het nu?
 
Verander

BOOL b = HttpSendRequest(hi_hor,NULL,0,(LPVOID)(LPCSTR)data,data.GetLength());

naar

BOOL b = HttpSendRequest(hi_hor,NULL,0,(LPVOID)(LPCSTR)data.c_str(),data.length());


Werkt het nu?

Thnx! :D het werkt!
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan