Panel użytkownika
Nazwa użytkownika:
Hasło:
Nie masz jeszcze konta?

Wininet POST/GET

Ostatnio zmodyfikowano 2017-07-29 18:32
Autor Wiadomość
foreman
Temat założony przez niniejszego użytkownika
Wininet POST/GET
» 2017-07-29 14:20:20
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 prosze o pomoc :D

#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;
}


jedyne co otrzymuje 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"&gt;

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <head> <title>Bad request!</title> <link rev="made" href="mailto:admin@example.com" /> <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.

If you think this is a server error, please contact the webmaster.

Error 400
<address> www.example.com
Apache/2.4.25 (Win32) OpenSSL/1.0.2j PHP/5.6.30 </address> </body> </html>
Press any key to continue . . .
[code]
P-163681
pekfos
» 2017-07-29 16:39:28
Wysyłasz dane jakby to było POST, a nie GET.
P-163692
foreman
Temat założony przez niniejszego użytkownika
nie za bardzo rozumiem
» 2017-07-29 17:03:51
Nie za bardzo rozumiem, myślałem iż różnica między Post i Get  jest tylko w funkcji HttpOpenRequest -->(lpszVerb )
P-163693
pekfos
» 2017-07-29 17:08:32
https://msdn.microsoft.com​/en-us/library/windows/desktop​/aa384247(v=vs.85).aspx
lpOptional [in]
A pointer to a buffer containing any optional data to be sent immediately after the request headers. This parameter is generally used for POST and PUT operations. The optional data can be the resource or information being posted to the server. This parameter can be NULL if there is no optional data to send.
Parametry GET są podane przy adresie strony, przykładowo:
https://www.google.pl/search​?q=wininet+how+to+send+get+request
P-163694
foreman
Temat założony przez niniejszego użytkownika
» 2017-07-29 17:17:54
ok mój bład lecz po zmianie

HttpSendRequest(
hData,
data,//lpszHeaders
sizeof(data),//dwHeadersLength
NULL,//lpOptional -->use for POST
0);

wyświetla sie tylko success i nic wiecej

------------------------------------------
edit: Oczywiście rozumiem jak działa metoda POST & GET tylko nie rozumiem  jeszcze jak je wysyłać za pomocą Wininet.
P-163695
pekfos
» 2017-07-29 17:21:46
A co powinieneś dostać? Bo wcześniej dostawałeś Bad Request.
P-163696
foreman
Temat założony przez niniejszego użytkownika
» 2017-07-29 17:24:36
Powinienem otrzymać wartość którą przekazuję GET'em skrypt PHP wyglada prosto
<?php
echo $_GET["p"];
?>
P-163697
pekfos
» 2017-07-29 17:28:08
I prawidłowo - dostajesz nic. Nie wspominałeś, że poza usunięciem wysyłania danych POST, dodałeś wysyłanie danych GET. Jeśli masz jakieś wątpliwości, to skorzystaj z linka, który podałem.
P-163698
« 1 » 2
  Strona 1 z 2 Następna strona