Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 287
  • Last Modified:

Help Need on CInternetSeccion

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("www.wrox.com");
       pFile = pHttpConnection->OpenRequest(CHttpConnection::HTTP_VERB_GET,"/");
      catch (CInternetException* pEx)

Thanks for your time.
1 Solution

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("www.bridgepath.com");
      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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now