Solved

HTTP Post using MFC

Posted on 1997-08-12
8
472 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
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
 
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

762 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now