资源简介
Wince下socket实现的HTTP类,支持POST和GET
代码片段和文件信息
/*******************************************************************************
* (C) Copyright 2008 Giant Electronics LTD
*
* These computer program listings and specifications are the property of Giant
* Electronics LTD and shall not be reproduced or copied or used in whole or in
* part without written permission from Giant Electronics LTD .
*
* Project: IViewer
* File Name: ClientHTTP.cpp
* Programer(s): Ben Zhan
* Created: 20080729
* Description: implementation of encapsulating HTTP protocol
* This class encapsulates HTTP protocol and provides the functionality to request
and read files on an HTTP server.
*******************************************************************************/
#include “stdafx.h“
#include “ClientHTTP.h“
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CClientHTTP::CClientHTTP()
{
}
CClientHTTP::~CClientHTTP()
{
}
//*******************************************************************************************************
// ValidHostChar:
// Return TRUE if the specified character is valid
// for a host name i.e. A-Z or 0-9 or -.:
//*******************************************************************************************************
BOOL CClientHTTP::ValidHostChar(TCHAR ch)
{
return( iswalpha(ch) || iswdigit(ch)|| ch==(‘-‘) || ch==(‘.‘) || ch==(‘:‘) );
}
void CClientHTTP::ParseURL(LPCSTR urlLPSTR protocolint lprotocolLPSTR hostint lhostLPSTR requestint lrequestint *port)
{
LPSTR workptrptr2;
//added by bpan
//reason: to avoid buffer overflow
//2008/09/29
int iMinLen;
*protocol = *host = *request = 0;
*port=80;
work = _strdup(url);
// _strupr(work);
ptr = strchr(work‘:‘); // find protocol if any
if(ptr!=NULL)
{
*(ptr++) = 0;
iMinLen = min(lprotocol-1 strlen(work));
strncpy(protocolwork iMinLen);
}
else
{
iMinLen = min(lprotocol -1 4);
strncpy(protocol“HTTP“ iMinLen);
ptr = work;
}
protocol[iMinLen] = TCHAR(‘\0‘);
if( (*ptr==‘/‘) && (*(ptr+1)==‘/‘) ) // skip past opening /‘s
ptr+=2;
ptr2 = ptr; // find host
while( ValidHostChar(*ptr2) && *ptr2 )
ptr2++;
*ptr2=0;
iMinLen = min(lhost -1 strlen(ptr));
strncpy(hostptr iMinLen);
host[iMinLen] = TCHAR(‘\0‘);
//lstrcpyn(hostptrlhost);
iMinLen = min(lrequest -1 strlen(url + (ptr2 - work)));
strncpy(requesturl+(ptr2-work) iMinLen); // find the request
request[iMinLen] = TCH
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 14049 2009-03-24 14:03 ClientHTTP.cpp
文件 3377 2009-03-24 14:03 ClientHTTP.h
文件 8118 2009-03-24 14:03 ClientSocket.cpp
文件 2584 2009-03-24 14:03 ClientSocket.h
文件 2268 2009-03-24 14:03 DaemonThread.h
文件 20526 2009-03-24 14:03 Internet.cpp
文件 9685 2009-03-24 14:03 Internet.h
----------- --------- ---------- ----- ----
60607 7
评论
共有 条评论