HTTP,CHTTPSocket,class,with,full,source,codef
Quick Search for:  in language:    
HTTP,CHTTPSocket,class,with,full,source,codef
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
C/ C++ Stats

 Code: 485,557 lines
 Jobs: 1,067 postings

 
Sponsored by:

 

You are in:

 
Login



Latest Code Ticker for C/ C++.
mini math programs
By Johno on 10/24


The matrix
By Alcodes on 10/24


Palindrome Finder
By Jonathan Volk on 10/24


processor identification and info
By Razvan Petrescu on 10/24


Login Interface using ncurses for Linux
By Suvoraj Biswas on 10/24


Matrix Encryption Algorithm
By Tony Fecteau on 10/23


SMALL TEXT GAME
By cJ! on 10/23


stod
By Mark Jundo P. Documento on 10/23


Basic Loops
By richard james on 10/23


Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!





Affiliate Sites



 
 
   

CHTTPSocket - Direct/ViaProxy - Reusable Class

Print
Email
 
VB icon
Submitted on: 1/13/2000
By: ATM  
Level: Advanced
User Rating: By 11 Users
Compatibility:C++ (general)

Users have accessed this code 12453 times.
 
 
     CHTTPSocket class with full source code, full qualified, one step, HTTP client. Can fetch pages from web, no problems if You try virtual host. If You use proxy server, only set some variables and get it worked also. I also compile sample application which You can download and test.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

//**************************************
//     
// Name: CHTTPSocket - Direct/ViaProxy -
//     Reusable Class
// Description:CHTTPSocket class with fu
//     ll source code,
full qualified, one step, HTTP client. Can fetch pages from web, no problems
if You try virtual host. If You use proxy server, only set some variables and
get it worked also. I also compile sample application which You can download
and test.
// By: ATM
//
//This code is copyrighted and has// limited warranties.Please see http://
//     www.Planet-Source-Code.com/xq/ASP/txtCod
//     eId.270/lngWId.3/qx/vb/scripts/ShowCode.
//     htm//for details.//**************************************
//     

//Download full source code from:
// http://www.tair.freeservers.com/
#include <stdio.h>
#include "httpsocket.h"
/************************************************************************
Sample derived class
************************************************************************/
class CMySock : public CHTTPSocket
    {
    char szErrMessage[255];
    public:
    	void OnError();
    	void OnResponse(); 
};

//error trigger void CMySock::OnError() { wsprintf(szErrMessage,"Error: %d, %d, %s",m_nErrCode,m_nExtErrCode,m_nErrInfo); MessageBox(NULL,szErrMessage,"Error",MB_OK); CHTTPSocket::OnError(); };
//response trigger void CMySock::OnResponse() { printf("----m_ulResponseSize=%d\r\n",m_ulResponseSize); printf("%s\r\n",(char *)m_szResponse); CHTTPSocket::OnResponse(); };
//-------------------------------------- // --------------------------------- //call style: //-------------------------------------- // --------------------------------- // dts.exe /URL http://www.yahoo.com [/P // RX 127.0.0.1] [/PRT 8080] //-------------------------------------- // --------------------------------- // where /URL - U see ///PRX - proxy's internet address ///PRT - proxy's port //-------------------------------------- // --------------------------------- // You must have KERNEL32.DLL, USER32.DL // L and WS2_32.DLL installed. //-------------------------------------- // --------------------------------- /************************************************************************ main. entry point for service ************************************************************************/ void main(int argc,char* argv[]) { CMySock cs; cs.m_bUseProxy=FALSE; int i=0; char* page=NULL; char* serverHost=NULL; char* serverPort=NULL; while(i<argc) { if (strcmp(argv[i],"/URL")==0) { if (argv[++i]!=NULL) page=argv[i]; else page=NULL; } if (strcmp(argv[i],"/PRX")==0) { if (argv[++i]!=NULL) serverHost=argv[i]; else serverHost=NULL; } if (strcmp(argv[i],"/PRT")==0) { if (argv[++i]!=NULL) serverPort=argv[i]; else serverPort=NULL; } i++; } if (page==NULL) { cs.ThrowError(0,0,"Please specify URL to fetch!"); return; } if (serverHost!=NULL) { //sets proxy server's internet address cs.SetServerHost((const char*)serverHost); i=0; if(serverPort!=NULL) i=atoi(serverPort); if (i==0) i=8080; //sets proxy server's port number (8080 by default) cs.m_nServerPort=i; //says use proxy to CHTTPSocket derived class cs.m_bUseProxy=TRUE; } printf("URL to fetch: %s\r\n",page); printf("Use proxy %s\r\n",serverHost); printf("Port for proxy %d\r\n",i); //page request here cs.Request(page); }
and CHTTPSocket interface: /************************************************************************ clicksocket.h ************************************************************************/ #ifndef __HTTPSOCKET__H__ #define __HTTPSOCKET__H__ #include <windows.h> //rem next line if no debug dump wanted // #define DEBON #include <stdio.h> //default send and recieve timeouts in s // ec #define HTTPRTIMEOUTDEF 90000 #define HTTPSTIMEOUTDEF 90000 #define MAXHOSTLENGTH65 #define MAXIPLENGTH 16 #define MAXBLOCKSIZE1024 #define MAXURLLENGTH255 #define MAXHEADERLENGTH 269 //primary error codes #define ERR_OK0 //if this error occurs, extended code is // WSA's error code #define ERR_WSAINTERNAL 1 #define ERR_URLNOTHING2 #define ERR_URLTOOLONG3 #define ERR_HOSTUNKNOWN 4 #define ERR_PROXYUNKNOWN 5 #define ERR_PROTOPARSE6 #define ERR_BADHOST 7 #define ERR_BADPORT 8 class CHTTPSocket { static int nInstanceCount; SOCKET sckHTTPSocket; struct sockaddr_in sinHTTPSocket; struct sockaddr_in sinHTTPServer; // remote server host address, size 64 b // ytes, 65th set to \0 char m_szServerHost[MAXHOSTLENGTH]; // host char m_szHost[MAXHOSTLENGTH]; // requested URI/URL char m_szURL[MAXURLLENGTH]; // remote server IP address, size 15 byt // es, 16th set to \0 char m_szServerHostIP[MAXIPLENGTH]; //-- Win32 specific WSADATAwsaData; void szcopy(char* dest,const char* src,int nMaxBytes); void szsent(SOCKET sckDest,const char* szHttp); public: // set to TRUE in InitInstance if TIME_W // AIT not need () bool m_bNoTimeWait; // recieve timeout change in InitInstanc // e intm_nRecvTimeout; // send timeout change in InitInstance intm_nSendTimeout; // remote server port int m_nServerPort; // use proxy flag bool m_bUseProxy; // error code int m_nErrCode; // extended error code; int m_nExtErrCode; // error info char m_nErrInfo[255]; // response content LPVOID m_szResponse; // response size ULONG m_ulResponseSize; public: //const/destr CHTTPSocket(); virtual ~CHTTPSocket(); //utils // sets proxy or http server's host void SetServerHost(const char* src); // sets proxy or http server's ip //(should be skipped if SetServerHost us // ed) void SetServerHostIP(const char* src); //starts request transaction void Request(const char* url="http://www.tair.freeservers.com"); //used for free memory allocated for pag // e //(should be skipped if You use CHTTPSoc // ket::OnResponse call in OnResponse) void memPostup(); //fire your OnError with specific error // cdes and message void ThrowError(int err, int xerr, const char* errdesc); //overridable //shoul be used for additional inits virtual bool InitInstance(); //trigger on any transaction error //(its great if U will call CHTTPSocket: // :OnError inside, //to free allocated memory pages) virtual void OnError(); //trigger on response recieved //(its great if U will call CHTTPSocket: // :OnResponse inside, //to free allocated memory pages) virtual void OnResponse(); };
#endif


Other 2 submission(s) by this author

 

 
Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:
 
Your Vote!

What do you think of this code(in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments

 There are no comments on this submission.
 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
Name:
Comment:

 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | C/ C++ Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.