HTTP Post using MFC

I am trying to do an HTTP Post from within a CGI script
(get input from the HTML form, parse it, post it to another
CGI, and get the result, parse again, and create HTML
output) but I'm not managing. I tried CHttpFile::Write/WriteString(), scince the CGI and the other
end awaits a standard input stream (HTTP POST), but to no
avail (I have a test CGI which reports what I've passed to it, and it allways reports an error). I know that writing to
standard input streams of the CGI at the other end is
possible, but how? Or am I looking in the wrong direction?

Pele

P.S. I'm new to experts-exchange and I'm sorry if the amount
of points I'm awarding for the answer is wrong.
peleAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

davmarcCommented:
CHttpFile relies on the WinInet library, which is designed for HTTP/FTP/Gopher *clients*, not servers.

If you are using standard CGI then you must deal with regular I/O function and classes - printf(), ostreams and so forth.
Should you decide to use ISAPI instead of CGI, you'll benefit from more speed and some additional MFC support.

Additional notes:
1) You posted this question twice. Delete the other copy.
2) The amount of points is never "wrong" - it is just the amount you think is fair. More points give your question more importance among the experts for their ranking. 50 points means you consider this question easy.

Davide Marcato.
0
davmarcCommented:
Could you please explain why my answer does not satisfy you?

Davide Marcato.
0
peleAuthor Commented:
I rejected your question because 1) you are telling me that "CHttpFile relies on the WinInet library, which is designed for HTTP/FTP/Gopher *clients*, not servers. ".
Scince my CGI _is_ a client (to another CGI), that means you are
telling me what (I think) I allready know.
And on the 2) I don't understand what you mean by "standard" CGI.
CGI == CGI.
But maybe I should rephrase my question:
How does one POST a HTML form from within a HTTP client, that client being written using MFC.
0
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

davmarcCommented:
1) CGI apps are HTTP *server* extensions. Call them "server-side" apps if you prefer, but they are not on the client sied of the HTTP transaction.

2) "Standard CGI" didn't mean there are other types of CGI (well WinCGI can be considered that but it has nothing to do with the question so I leave it out)...the alternative is ISAPI, which has  a target similar to the one of CGI but Windows-specific implementation details, that's why I called CGI "standard". It's been my improper use of the word.

I think we are misunderstanding our words.
Will your code run on the server machine or on client machines?

Davide Marcato.
0
peleAuthor Commented:
1) CGI apps are HTTP server extensions, but in this case (if you've read the question carefully) it's _both_ a server _and_ a client to another CGI.
This is how it (is supposed to) work(s):

WebBrowser -> MyCGI -> OtherCGI -> MyCGI -> WebBrowser.

Is this ok now?
Regards,

Pele

P.S. My code will run on a Server machine to your Joe Nation's WebBrowser, but at the same time it is a CLIENT to another Server.
(which in turn is a Server to MyCGI, but that Server in itself is also a client to a databse backend - so we're not talking about three-tier applications anymore, it's 4-tier. It would be nice if I could talk straight to that databse backend I know, but I can't, for security reasons).
0
syjwgCommented:
If I'm not totaly lost, this could perhaps help you:
1) Create a .BAT file containing following:
type stdin.txt | The_Other_CGI.exe > stdout.txt
2) From your CGIprogram create the stdin.txt file
and use CreateProcess() to start the .BAT file and wait
for it to complete (WaitForSingleObject()).
3) Read stdout.txt and do whatever...
 

0
mikeblasCommented:
You don't show your code, so it's hard to be sure that I fully understand what you're doing.  You say you're calling Write() and WriteString(), though. If you're performing a POST, you should not call CHttpFile::Write() or CHttpFile::WriteString() to pass the posted data. Instead, you should pass the data to be posted with the lpOptional and dwOptionalLen parameters to the CHttpFile::SendRequest() function.

You're right, by the way, in noting that davmarc is confused. You are on the client side of the connection you're trying to make even if your code is running on the server.

.B ekiM

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
davmarcCommented:
I don't think I am confused in this case. His CGI app is both on the server side of a connection *and* on the client side of another, hence the misundestanding about which one he wanted help for. If you read my second comment again, I stated he is on the "server side of the HTTP transaction". Everything was clarified definitively by his last comment, anyway.

Davide Marcato.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.