Solved

HTTP Post using MFC

Posted on 1997-08-12
8
483 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.
0
Comment
Question by:pele
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 4

Expert Comment

by:davmarc
ID: 1303570
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
 
LVL 4

Expert Comment

by:davmarc
ID: 1303571
Could you please explain why my answer does not satisfy you?

Davide Marcato.
0
 

Author Comment

by:pele
ID: 1303572
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Expert Comment

by:davmarc
ID: 1303573
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
 

Author Comment

by:pele
ID: 1303574
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
 

Expert Comment

by:syjwg
ID: 1303575
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
 
LVL 11

Accepted Solution

by:
mikeblas earned 70 total points
ID: 1303576
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
 
LVL 4

Expert Comment

by:davmarc
ID: 1303577
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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question