Posting form using WinHttp

user963241 picture user963241 · Dec 25, 2010 · Viewed 9.7k times · Source

Do i need to add any headers before making a post to server?

For example, Currently I'm trying to send a request along with the post data this way,

  LPCWSTR post = L"name=User&subject=Hi&message=Hi";

    if (!(WinHttpSendRequest( hRequest, 
                            WINHTTP_NO_ADDITIONAL_HEADERS,
                            0, (LPVOID)post, wcslen(post), 
                            wcslen(post), 0)))
    {
          //error
    }

should this work?

Answer

OhadM picture OhadM · Feb 4, 2015

What worked for me:

    LPSTR  post = "log=test";//in my php file: if(isset($_POST['log']))
    hRequest = WinHttpOpenRequest(hConnect,
                                    L"POST",
                                    L"/test.php",
                                    NULL,
                                    WINHTTP_NO_REFERER,
                                    WINHTTP_DEFAULT_ACCEPT_TYPES,
                                    0);
    bResults = WinHttpSendRequest(hRequest,
                                    L"content-type:application/x-www-form-urlencoded",
                                    -1,
                                    post,
                                    strlen(post),
                                    strlen(post),
                                    NULL);