Cześć mam problem, odnośnie lib'a Wininet zgodnie z API stworzyłem internetOpen(), InternetConnect(), HttpOpenRequest(), HttpSendRequest()
i kod php wyświetlajacy tylko to co leci po GET. jesli ktoś wie jak wyslac poprawnie dane to porsze o podpowiedź
#include "stdafx.h"
#include <windows.h>
#include <iostream>
#include <wininet.h>
#include <cstdlib>
#include <string>
#pragma comment(lib,"Wininet.lib")
CHAR buffer[2048];
LPCWSTR m_strContents;
DWORD dwRead;
LPCWSTR UserAgent = L"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36";
LPCWSTR HOST = L"localhost";
static TCHAR hdrs[] =_T("Content-Type: application/x-www-form-urlencoded");
int main()
{
HINTERNET hinternet = InternetOpen(
UserAgent,
INTERNET_OPEN_TYPE_PRECONFIG,
NULL,
NULL,
0);
HINTERNET hsite = InternetConnect(
hinternet,
HOST,
INTERNET_DEFAULT_HTTPS_PORT,
NULL,
NULL,
INTERNET_SERVICE_HTTP,
0,
0);
if (hsite != NULL)
std::cout << "success" <<std::endl;
HINTERNET hData = HttpOpenRequest(
hsite,
L"GET",//GET
L"/test.php",
NULL,
NULL,
NULL,
INTERNET_FLAG_KEEP_CONNECTION,
0);
static TCHAR data[] =
_T("p=test");
HttpSendRequest(
hData,
hdrs,
sizeof(hdrs),
data,
sizeof(data));
InternetReadFile(hData, buffer, 1255, &dwRead);
std::cout << buffer;
system("pause");
return 0;
}
No i kod php
<?php
echo $_GET["p"];
?>
jedyne co dostaje to :
success<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <head> <title>Bad request!</title> <link rev="made" href="mailto:[email protected]" /> <style type="text/css">/*><!--*/ body { color: #000000; background-color: #FFFFFF; } a:link { color: #0000CC; } p, address {margin-left: 3em;} span {font-size: smaller;} /**/--></style> </head> <body>Bad request!
Your browser (or proxy) sent a request that
this server could not understand.
</p>
If you think this is a server error, please contact the webmaster.
Error 400
<address> www.example.comApache/2.4.25 (Win32) OpenSSL/1.0.2j PHP/5.6.30 </address> </body> </html>
Press any key to continue . . .