We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

HTTP Post using MFC

pele
pele asked
on
Medium Priority
514 Views
Last Modified: 2013-11-19
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.
Comment
Watch Question

Commented:
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.

Commented:
Could you please explain why my answer does not satisfy you?

Davide Marcato.

Author

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.

Commented:
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.

Author

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).

Commented:
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...
 

Commented:
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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Commented:
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.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.