• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 432
  • Last Modified:

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);
0
Lucidity
Asked:
Lucidity
1 Solution
 
jhanceCommented:
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"));
}
0
 
chensuCommented:
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
0
 
mikeblasCommented:
> 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
0
 
LucidityAuthor Commented:
chensus worked out great, answer again and I will give you the points.

thanks
0
 
chensuCommented:
Thank you.
0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now