Help Need on CInternetSeccion

Posted on 1998-04-23
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;

       pHttpConnection = Connection.GetHttpConnection("");
       pFile = pHttpConnection->OpenRequest(CHttpConnection::HTTP_VERB_GET,"/");
      catch (CInternetException* pEx)

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

Accepted Solution

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__;

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;
      CInternetSession sess("YourAgent");

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

      CString strPost(
      pFile->SendRequest(strHeaders, (LPVOID)(LPCTSTR) strPost, strPost.GetLength());

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

      delete pFile;

   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


Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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…
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.
Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

744 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

11 Experts available now in Live!

Get 1:1 Help Now