[WININET]Problem mit Post Request



  • Hey,

    ich habe ein Problem, einen Post Request zu erstellen.

    #include <Windows.h>
    #include <Wininet.h>
    #include <string>
    using namespace std;
    int main()
    {
    	HINTERNET Initialize,Connection,File;
    	DWORD dwBytes;
    	char ch;
    	Initialize = InternetOpenW(L"HTTPGET",INTERNET_OPEN_TYPE_DIRECT,NULL,NULL,0);
    	Connection = InternetConnectW(Initialize,L"127.0.0.1",INTERNET_DEFAULT_HTTP_PORT,
    	NULL,NULL,INTERNET_SERVICE_HTTP,0,0);
    	//L"HTTP/1.1"
    	File = HttpOpenRequestW(Connection,L"POST",L"/yop.php",NULL,NULL,NULL,0,1);
    
    	if(HttpSendRequestW(File,ws_Headers.c_str(), ws_Headers.size(),L"name=John+Doe", ws_post.size()))
    	{
    		while(InternetReadFile(File,&ch,1,&dwBytes))
    		{
    			if(dwBytes != 1)break;
    			putchar(ch);
    		}
    	}
    	InternetCloseHandle(File);
    	InternetCloseHandle(Connection);
    	InternetCloseHandle(Initialize);
    }
    

    Der Netzwerksniffer sagt:

    POST /yop.php HTTP/1.1
    Content-Type: application/x-www-form-urlencoded
    User-Agent: HTTPGET
    Host: 127.0.0.1
    Content-Length: 13
    Cache-Control: no-cache
    n.a.m.e.=.J.oHTTP/1.1 200 OK

    Wie man sieht wird die Postvariable falsch gesendet.
    Wie kann ich das Problem lösen?

    mfg

    Trollkirsche



  • oh sry, hier die Variablen:

    wstring ws_Headers = L"Content-Type: application/x-www-form-urlencoded";
       wstring ws_post =L"name=John+Doe";
    

    ich hoffe ihr könnt mir helfen 🙂

    mfg

    Trollkirsche



  • Ich habe es auch mit dem convertieren zu UTF-8 ausprobiert, bringt leider nichts 😞

    WideCharToMultiByte(CP_UTF8, 0, &ws_post[0], ws_post.size(), NULL, 0, NULL, NULL);
    	WideCharToMultiByte(CP_UTF8, 0, &ws_Headers[0],ws_Headers.size(), NULL, 0, NULL, NULL);
    

    mfg

    Trollkirsche



  • HTTP versteht kein Unicode sondern nur ASCII... Du musst also das "lpOptional" als ASCII versenden (optional entsprechend encoded)


Anmelden zum Antworten