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
Solved

Help Need on CInternetSeccion

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

Title # Comments Views Activity
not able to insert into temp table 68 169
NotAlone Challenge 20 84
Making an alias 7 101
Capture logon name 13 87
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

856 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