Link to home
Start Free TrialLog in
Avatar of Lucidity
Lucidity

asked on

How to POST form variables???

I want to make a client app that posts information to specific web sites cgi-scripts.  CHttpConnection supports a POST action but I cannot find anyother infor on how to POST data in a way that a CGI script would expect form data.



    CInternetSession is(_T("HTTPGET"));
    CHttpConnection *pHC = NULL;
    CHttpFile *pHF = NULL;
    try
    {
        pHC = is.GetHttpConnection(_T(Server));
        pHF = pHC->OpenRequest(_T(Token), _T(Request), NULL, 0,
                               NULL, NULL, 0);
Avatar of jhance
jhance

Just use the SendRequest() method to send the POST data along to the server:

try
    {
        pHC = is.GetHttpConnection(_T(Server));
        pHF = pHC->OpenRequest(_T(Token), _T(Request), NULL,0,NULL,NULL, 0);

pHF->SendRequest(NULL, 0, "item=item_val", strlen("item=item_val"));
}
That won't work. You need to send the "Content-Type: application/x-www-form-urlencoded" header. See

HOWTO: Simulate a Form POST Request Using WinInet
http://support.microsoft.com/support/kb/articles/Q165/2/98.ASP
> That won't work.

Maybe it will, maybe it won't. Some parsesrs require that header and some don't. Some require other headers, or even a cookie.

..B ekiM
Avatar of Lucidity

ASKER

chensus worked out great, answer again and I will give you the points.

thanks
ASKER CERTIFIED SOLUTION
Avatar of chensu
chensu
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial