Solved

Help Need on CInternetSeccion

Posted on 1998-04-23
1
237 Views
Last Modified: 2013-11-19
I'm starting to learn visual C++. I need to build a client which will connect to a server and
send a cgi text. The server will convert it to a wave format and send it back.
Could I use CHhttpConnection HTTP_VERB_POST to OpenRequest and then send a a
pointer this points to the string to be converted.

Can I execute this file form dos command. If so How?
CInternetSession Connection;
      CHttpConnection* pHttpConnection = NULL;
      CHttpFile* pFile = NULL;

      try
      {
       pHttpConnection = Connection.GetHttpConnection("www.wrox.com");
       pFile = pHttpConnection->OpenRequest(CHttpConnection::HTTP_VERB_GET,"/");
       pFile->SendRequest();      
      }
      catch (CInternetException* pEx)
      {
            pEx->ReportError();
            pEx->Delete();

Thanks for your time.
0
Comment
Question by:aa04
1 Comment
 
LVL 11

Accepted Solution

by:
mikeblas earned 100 total points
ID: 1301623

This code will use HTTP_VERB_POST to send a form to the server.

// compile me for debug with:
// cl /Zi /MTd doit.cpp
// compile me for release with:
// cl /MT doit.cpp

#include <afx.h>
#include <afxwin.h>
#include <afxinet.h>
#include <iostream>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

CWinApp theApp;

using namespace std;

CString strHeaders =
"Content-Type: application/x-www-form-urlencoded\r\n\r\n";

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
   int nRetCode = 0;

   //REVIEW: this app does no error-checking whatsoever

   if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
   {
      cerr << _T("Fatal Error: MFC initialization failed") << endl;
      nRetCode = 1;
   }
   else
   {
      CInternetSession sess("YourAgent");

      CHttpConnection* pConnection = sess.GetHttpConnection("www.bridgepath.com");
      CHttpFile *pFile = NULL;
      pFile = pConnection->OpenRequest("POST", "/jobseek/inputinitial.cfm");

      CString strPost(
         "email=spaceape@nowhere.net&"
         "email_required=Your+e-mail+address+is+required+to+continue.&"
         "brand=BridgePath");
 
      pFile->SendRequest(strHeaders, (LPVOID)(LPCTSTR) strPost, strPost.GetLength());

      CString str;
      while (pFile->ReadString(str))
      {
         cout << (LPCTSTR) str;
         cout << endl;
      }

      pFile->Close();
      delete pFile;
      pConnection->Close();
   }

   return nRetCode;
}



If you want to have the server convert some data from one format to another and return it, you'll need to write software on the server side to do that. And you'll need to make sure what you POST, and the way you read it back, exactly matches what's going on with the server software.

.B ekiM

0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Adapt this command to show who installed 29 108
Looking for a specific application/software 2 110
unable to delete all specified values regedit 38 408
substring method in java 1 120
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

770 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