Initial
This commit is contained in:
63
wininet/HTTPConnection.cpp
Normal file
63
wininet/HTTPConnection.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
#include <wininet/HTTPConnection.hpp>
|
||||
|
||||
bool HTTPConnection::get(const String &action,HTTPHeader &httpHeader,HTTPData &httpData)
|
||||
{
|
||||
DWORD dwSize(0);
|
||||
String strHeaders;
|
||||
|
||||
LPSTR accessTypes[2]={"*/*",0};
|
||||
if(!isOkay())return false;
|
||||
mhRequest=::HttpOpenRequest(getHANDLE(),"GET",action.str(),HTTP_VERSION,0,(const char**)&accessTypes,INTERNET_FLAG_RELOAD|INTERNET_FLAG_NO_CACHE_WRITE,0);
|
||||
if(!mhRequest)return false;
|
||||
if(!::HttpSendRequest(mhRequest,0,0,0,0))return false;
|
||||
::HttpQueryInfo(mhRequest,HTTP_QUERY_RAW_HEADERS_CRLF,0,&dwSize,0);
|
||||
if(!dwSize)return false;
|
||||
strHeaders.reserve(dwSize+1);
|
||||
::HttpQueryInfo(mhRequest,HTTP_QUERY_RAW_HEADERS_CRLF,strHeaders,&dwSize,0);
|
||||
httpHeader=strHeaders;
|
||||
if(httpHeader.isErrorResponse())return false;
|
||||
httpData.size(httpHeader.getContentLength());
|
||||
if(!httpData.size())httpData.size(32768);
|
||||
dwSize=0;
|
||||
::InternetReadFile(mhRequest,&httpData[0],httpData.size(),&dwSize);
|
||||
if(dwSize<httpData.size())
|
||||
{
|
||||
HTTPData tmpData;
|
||||
tmpData.size(dwSize);
|
||||
for(int index=0;index<dwSize;index++)tmpData[index]=httpData[index];
|
||||
httpData=tmpData;
|
||||
}
|
||||
closeRequest();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool HTTPConnection::post(const String &action,HTTPHeader &httpHeader,HTTPData &httpData)
|
||||
{
|
||||
DWORD dwSize(0);
|
||||
String strHeader;
|
||||
String strHeaders;
|
||||
|
||||
LPSTR accept[2]={"Accept: */*",0};
|
||||
if(!isOkay())return false;
|
||||
mhRequest=::HttpOpenRequest(getHANDLE(),"GET",action.str(),HTTP_VERSION,0,(const char**)&accept,0,1);
|
||||
if(!mhRequest)return false;
|
||||
strHeader=httpHeader.serialize();
|
||||
if(!::HttpSendRequest(mhRequest,strHeader.str(),strHeader.length(),&httpData[0],httpData.size()))return false;
|
||||
::HttpQueryInfo(mhRequest,HTTP_QUERY_RAW_HEADERS_CRLF,0,&dwSize,0);
|
||||
if(!dwSize)return false;
|
||||
strHeaders.reserve(dwSize+1);
|
||||
::HttpQueryInfo(mhRequest,HTTP_QUERY_RAW_HEADERS_CRLF,strHeaders,&dwSize,0);
|
||||
httpHeader=strHeaders;
|
||||
httpData.size(httpHeader.getContentLength());
|
||||
if(!httpData.size())httpData.size(32768);
|
||||
::InternetReadFile(mhRequest,&httpData[0],httpData.size(),&dwSize);
|
||||
if(dwSize<httpData.size())
|
||||
{
|
||||
HTTPData tmpData;
|
||||
tmpData.size(dwSize);
|
||||
for(int index=0;index<dwSize;index++)tmpData[index]=httpData[index];
|
||||
httpData=tmpData;
|
||||
}
|
||||
closeRequest();
|
||||
return true;
|
||||
}
|
||||
101
wininet/HTTPConnection.hpp
Normal file
101
wininet/HTTPConnection.hpp
Normal file
@@ -0,0 +1,101 @@
|
||||
#ifndef _WININET_HTTPCONNECTION_HPP_
|
||||
#define _WININET_HTTPCONNECTION_HPP_
|
||||
#ifndef _COMMON_STRING_HPP_
|
||||
#include <common/string.hpp>
|
||||
#endif
|
||||
#ifndef _COMMON_BLOCK_HPP_
|
||||
#include <common/block.hpp>
|
||||
#endif
|
||||
#ifndef _COMMON_ARRAY_HPP_
|
||||
#include <common/array.hpp>
|
||||
#endif
|
||||
#ifndef _WININET_INTERNET_HPP_
|
||||
#include <wininet/internet.hpp>
|
||||
#endif
|
||||
#ifndef _WININET_CONNECTION_HPP_
|
||||
#include <wininet/connection.hpp>
|
||||
#endif
|
||||
#ifndef _WININET_HTTPHEADER_HPP_
|
||||
#include <wininet/HTTPHeader.hpp>
|
||||
#endif
|
||||
#ifndef _WININET_HTTPDATA_HPP_
|
||||
#include <wininet/HTTPData.hpp>
|
||||
#endif
|
||||
|
||||
class HTTPConnection : private Connection
|
||||
{
|
||||
public:
|
||||
HTTPConnection(void);
|
||||
HTTPConnection(const Internet &internet,const String &strServer,int port=INTERNET_DEFAULT_HTTP_PORT);
|
||||
virtual ~HTTPConnection();
|
||||
bool connect(const Internet &internet,const String &strServer,int port=INTERNET_DEFAULT_HTTP_PORT);
|
||||
bool get(HTTPHeader &httpHeader,HTTPData &httpData);
|
||||
bool get(const String &action,HTTPHeader &httpHeader,HTTPData &httpData);
|
||||
bool post(const String &action,HTTPHeader &httpHeader,HTTPData &httpData);
|
||||
void close(void);
|
||||
private:
|
||||
HTTPConnection(const HTTPConnection &httpConnection);
|
||||
HTTPConnection &operator=(const HTTPConnection &httpConnection);
|
||||
void closeRequest(void);
|
||||
void createHeaderLines(String &strLines,Block<String> &headerLines);
|
||||
|
||||
HINTERNET mhRequest;
|
||||
};
|
||||
|
||||
inline
|
||||
HTTPConnection::HTTPConnection()
|
||||
: mhRequest(0)
|
||||
{
|
||||
}
|
||||
|
||||
inline
|
||||
HTTPConnection::HTTPConnection(const HTTPConnection &httpConnection)
|
||||
{ // private
|
||||
}
|
||||
|
||||
inline
|
||||
HTTPConnection &HTTPConnection::operator=(const HTTPConnection &httpConnection)
|
||||
{ // private
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline
|
||||
HTTPConnection::HTTPConnection(const Internet &internet,const String &strServer,int port)
|
||||
{
|
||||
connect(internet,strServer,port);
|
||||
}
|
||||
|
||||
inline
|
||||
HTTPConnection::~HTTPConnection()
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
inline
|
||||
bool HTTPConnection::connect(const Internet &internet,const String &strServer,int port)
|
||||
{
|
||||
if(!internet.isOkay())return false;
|
||||
return Connection::connect(internet,strServer,INTERNET_SERVICE_HTTP,port);
|
||||
}
|
||||
|
||||
inline
|
||||
bool HTTPConnection::get(HTTPHeader &httpHeader,HTTPData &httpData)
|
||||
{
|
||||
return get(String(),httpHeader,httpData);
|
||||
}
|
||||
|
||||
inline
|
||||
void HTTPConnection::close(void)
|
||||
{
|
||||
Connection::close();
|
||||
closeRequest();
|
||||
}
|
||||
|
||||
inline
|
||||
void HTTPConnection::closeRequest(void)
|
||||
{
|
||||
if(!mhRequest)return;
|
||||
::InternetCloseHandle(mhRequest);
|
||||
mhRequest=0;
|
||||
}
|
||||
#endif
|
||||
10
wininet/HTTPData.cpp
Normal file
10
wininet/HTTPData.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
#include <wininet/HTTPData.hpp>
|
||||
|
||||
String HTTPData::toString(void)const
|
||||
{
|
||||
String str;
|
||||
|
||||
str.reserve(1024);
|
||||
for(int index=0;index<size();index++)str+=((Array<BYTE>&)*this).operator[](index);
|
||||
return str;
|
||||
}
|
||||
37
wininet/HTTPData.hpp
Normal file
37
wininet/HTTPData.hpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#ifndef _WININET_HTTPDATA_HPP_
|
||||
#define _WININET_HTTPDATA_HPP_
|
||||
#ifndef _COMMON_ARRAY_HPP_
|
||||
#include <common/array.hpp>
|
||||
#endif
|
||||
|
||||
class HTTPData : public Array<BYTE>
|
||||
{
|
||||
public:
|
||||
HTTPData();
|
||||
virtual ~HTTPData();
|
||||
HTTPData &operator=(const String &string);
|
||||
String toString(void)const;
|
||||
private:
|
||||
};
|
||||
|
||||
inline
|
||||
HTTPData::HTTPData()
|
||||
{
|
||||
}
|
||||
|
||||
inline
|
||||
HTTPData::~HTTPData()
|
||||
{
|
||||
}
|
||||
|
||||
inline
|
||||
HTTPData &HTTPData::operator=(const String &string)
|
||||
{
|
||||
int strLength;
|
||||
|
||||
if(string.isNull()||0==(strLength=string.length()))return *this;
|
||||
size(strLength);
|
||||
::memcpy(&operator[](0),string.str(),strLength);
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
63
wininet/HTTPHeader.cpp
Normal file
63
wininet/HTTPHeader.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
#include <wininet/HTTPHeader.hpp>
|
||||
|
||||
void HTTPHeader::parseHeader(Block<String> &headerLines)
|
||||
{
|
||||
for(int index=0;index<headerLines.size();index++)
|
||||
{
|
||||
const String &headerLine=headerLines[index];
|
||||
const String strToken=headerLine.betweenString(0,':');
|
||||
if(!index)mResponseCode=headerLine.betweenString(' ',' ').toInt();
|
||||
if(strToken=="Date")mDate=headerLine.betweenString(' ',0);
|
||||
else if(strToken=="Server")mServer=headerLine.betweenString(' ',0);
|
||||
else if(strToken=="Last-Modified")mLastModified=headerLine.betweenString(' ',0);
|
||||
else if(strToken=="ETag")mETag=headerLine.betweenString(' ',0);
|
||||
else if(strToken=="Accept-Ranges")mAcceptRanges=headerLine.betweenString(' ',0);
|
||||
else if(strToken=="Content-Length")mContentLength=headerLine.betweenString(' ',0).toInt();
|
||||
else if(strToken=="Content-Type")mContentType=headerLine.betweenString(' ',0);
|
||||
else if(strToken=="Accept")mAccept=headerLine.betweenString(' ',0);
|
||||
}
|
||||
}
|
||||
|
||||
void HTTPHeader::parseHeader(const String &headerLines)
|
||||
{
|
||||
Block<String> blkHeaderLines;
|
||||
createHeaderLines(headerLines,blkHeaderLines);
|
||||
*this=blkHeaderLines;
|
||||
}
|
||||
|
||||
void HTTPHeader::createHeaderLines(String strHeaders,Block<String> &headerLines)
|
||||
{
|
||||
char *strPtr=0;
|
||||
headerLines.remove();
|
||||
if(strHeaders.isNull())return;
|
||||
strPtr=strHeaders.str();
|
||||
strPtr=::strtok(strPtr,"\n\0");
|
||||
while(true)
|
||||
{
|
||||
if(!strPtr)break;
|
||||
String str=strPtr;
|
||||
str.removeTokens("\r\n");
|
||||
headerLines.insert(&str);
|
||||
strPtr=::strtok(0,"\n\0");
|
||||
}
|
||||
}
|
||||
|
||||
String HTTPHeader::serialize(void)
|
||||
{
|
||||
String strHeader;
|
||||
String crlf="\r\n";
|
||||
|
||||
if(!mDate.isNull())strHeader+=String("Date: ")+mDate+crlf;
|
||||
if(!mServer.isNull())strHeader+=String("Server: ")+mServer+crlf;
|
||||
if(!mLastModified.isNull())strHeader+=String("Last-Modified: ")+mLastModified+crlf;
|
||||
if(!mETag.isNull())strHeader+=String("ETag: ")+mETag+crlf;
|
||||
if(!mAcceptRanges.isNull())strHeader+=String("Accept-Ranges: ")+mAcceptRanges+crlf;
|
||||
if(0!=mContentLength)strHeader+=String("Content-Length :")+String().fromInt(mContentLength)+crlf;
|
||||
if(!mContentType.isNull())strHeader+=String("Content-Type: ")+mContentType+crlf;
|
||||
return strHeader;
|
||||
}
|
||||
|
||||
String HTTPHeader::getApplicationExtension(void)const
|
||||
{
|
||||
return String(".")+mContentType.betweenString('/',0);
|
||||
}
|
||||
217
wininet/HTTPHeader.hpp
Normal file
217
wininet/HTTPHeader.hpp
Normal file
@@ -0,0 +1,217 @@
|
||||
#ifndef _WININET_HTTPHEADER_HPP_
|
||||
#define _WININET_HTTPHEADER_HPP_
|
||||
#ifndef _COMMON_BLOCK_HPP_
|
||||
#include <common/block.hpp>
|
||||
#endif
|
||||
#ifndef _COMMON_STRING_HPP_
|
||||
#include <common/string.hpp>
|
||||
#endif
|
||||
#ifndef _WININET_SERIALIZEABLE_HPP_
|
||||
#include <wininet/serializeable.hpp>
|
||||
#endif
|
||||
|
||||
class ContentType
|
||||
{
|
||||
public:
|
||||
typedef enum ContentTypeConst{MultipartFormData,ApplicationWWWFormURLEncoded};
|
||||
static String getContentType(ContentTypeConst contentTypeConst);
|
||||
};
|
||||
|
||||
inline
|
||||
String ContentType::getContentType(ContentTypeConst contentTypeConst)
|
||||
{
|
||||
switch(contentTypeConst)
|
||||
{
|
||||
case MultipartFormData :
|
||||
return "multipart/form-data";
|
||||
case ApplicationWWWFormURLEncoded :
|
||||
default :
|
||||
return "application/x-www-form-urlencoded";
|
||||
}
|
||||
}
|
||||
|
||||
class HTTPHeader : public Serializeable
|
||||
{
|
||||
public:
|
||||
HTTPHeader();
|
||||
HTTPHeader(Block<String> &headerLines);
|
||||
HTTPHeader(const String &headerLines);
|
||||
virtual ~HTTPHeader();
|
||||
HTTPHeader &operator=(Block<String> &headerLines);
|
||||
HTTPHeader &operator=(const String &headerLines);
|
||||
const String &getDate(void)const;
|
||||
void setDate(const String &date);
|
||||
const String &getServer(void)const;
|
||||
void setServer(const String &server);
|
||||
const String &getLastModified(void)const;
|
||||
void setLastModified(const String &lastModified);
|
||||
const String &getETag(void)const;
|
||||
void setETag(const String &eTag);
|
||||
int getContentLength(void)const;
|
||||
void setContentLength(int contentLength);
|
||||
const String &getContentType(void)const;
|
||||
void setContentType(const String &contentType);
|
||||
const String &getAccept(void)const;
|
||||
void setAccept(const String &accept);
|
||||
int getResponseCode(void)const;
|
||||
void setResponseCode(int responseCode);
|
||||
bool isErrorResponse(void)const;
|
||||
String getApplicationExtension(void)const;
|
||||
String serialize(void);
|
||||
private:
|
||||
void parseHeader(Block<String> &headerLines);
|
||||
void parseHeader(const String &headerLines);
|
||||
void createHeaderLines(String strHeaders,Block<String> &headerLines);
|
||||
|
||||
String mDate;
|
||||
String mServer;
|
||||
String mLastModified;
|
||||
String mETag;
|
||||
String mAcceptRanges;
|
||||
int mContentLength;
|
||||
String mContentType;
|
||||
String mAccept;
|
||||
int mResponseCode;
|
||||
};
|
||||
|
||||
inline
|
||||
HTTPHeader::HTTPHeader()
|
||||
: mContentLength(0), mResponseCode(0), mContentType("application/x-www-form-urlencoded")
|
||||
{
|
||||
}
|
||||
|
||||
inline
|
||||
HTTPHeader::HTTPHeader(Block<String> &headerLines)
|
||||
{
|
||||
parseHeader(headerLines);
|
||||
}
|
||||
|
||||
inline
|
||||
HTTPHeader::HTTPHeader(const String &headerLines)
|
||||
{
|
||||
parseHeader(headerLines);
|
||||
}
|
||||
|
||||
inline
|
||||
HTTPHeader::~HTTPHeader()
|
||||
{
|
||||
}
|
||||
|
||||
inline
|
||||
HTTPHeader &HTTPHeader::operator=(Block<String> &headerLines)
|
||||
{
|
||||
parseHeader(headerLines);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline
|
||||
HTTPHeader &HTTPHeader::operator=(const String &headerLines)
|
||||
{
|
||||
parseHeader(headerLines);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline
|
||||
const String &HTTPHeader::getDate(void)const
|
||||
{
|
||||
return mDate;
|
||||
}
|
||||
|
||||
inline
|
||||
void HTTPHeader::setDate(const String &date)
|
||||
{
|
||||
mDate=date;
|
||||
}
|
||||
|
||||
inline
|
||||
const String &HTTPHeader::getServer(void)const
|
||||
{
|
||||
return mServer;
|
||||
}
|
||||
|
||||
inline
|
||||
void HTTPHeader::setServer(const String &server)
|
||||
{
|
||||
mServer=server;
|
||||
}
|
||||
|
||||
inline
|
||||
const String &HTTPHeader::getLastModified(void)const
|
||||
{
|
||||
return mLastModified;
|
||||
}
|
||||
|
||||
inline
|
||||
void HTTPHeader::setLastModified(const String &lastModified)
|
||||
{
|
||||
mLastModified=lastModified;
|
||||
}
|
||||
|
||||
inline
|
||||
const String &HTTPHeader::getETag(void)const
|
||||
{
|
||||
return mETag;
|
||||
}
|
||||
|
||||
inline
|
||||
void HTTPHeader::setETag(const String &eTag)
|
||||
{
|
||||
mETag=eTag;
|
||||
}
|
||||
|
||||
inline
|
||||
int HTTPHeader::getContentLength(void)const
|
||||
{
|
||||
return mContentLength;
|
||||
}
|
||||
|
||||
inline
|
||||
void HTTPHeader::setContentLength(int contentLength)
|
||||
{
|
||||
mContentLength=contentLength;
|
||||
}
|
||||
|
||||
inline
|
||||
const String &HTTPHeader::getContentType(void)const
|
||||
{
|
||||
return mContentType;
|
||||
}
|
||||
|
||||
inline
|
||||
void HTTPHeader::setContentType(const String &contentType)
|
||||
{
|
||||
mContentType=contentType;
|
||||
}
|
||||
|
||||
inline
|
||||
const String &HTTPHeader::getAccept(void)const
|
||||
{
|
||||
return mAccept;
|
||||
}
|
||||
|
||||
inline
|
||||
void HTTPHeader::setAccept(const String &accept)
|
||||
{
|
||||
mAccept=accept;
|
||||
}
|
||||
|
||||
inline
|
||||
int HTTPHeader::getResponseCode(void)const
|
||||
{
|
||||
return mResponseCode;
|
||||
}
|
||||
|
||||
inline
|
||||
void HTTPHeader::setResponseCode(int responseCode)
|
||||
{
|
||||
mResponseCode=responseCode;
|
||||
}
|
||||
|
||||
inline
|
||||
bool HTTPHeader::isErrorResponse(void)const
|
||||
{
|
||||
return getResponseCode()>=500;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
92
wininet/Internet.hpp
Normal file
92
wininet/Internet.hpp
Normal file
@@ -0,0 +1,92 @@
|
||||
#ifndef _WININET_INTERNET_HPP_
|
||||
#define _WININET_INTERNET_HPP_
|
||||
#ifndef _COMMON_EXCEPTION_HPP_
|
||||
#include <common/except.hpp>
|
||||
#endif
|
||||
#ifndef _COMMON_REGKEY_HPP_
|
||||
#include <common/regkey.hpp>
|
||||
#endif
|
||||
#ifndef _COMMON_WININET_HPP_
|
||||
#include <common/wininet.hpp>
|
||||
#endif
|
||||
|
||||
class Internet
|
||||
{
|
||||
public:
|
||||
typedef enum AccessType{OpenDirect=INTERNET_OPEN_TYPE_DIRECT,PreConfig=INTERNET_OPEN_TYPE_PRECONFIG,NoAutoProxy=
|
||||
INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY,Proxy=INTERNET_OPEN_TYPE_PROXY};
|
||||
typedef enum Flags{Async=INTERNET_FLAG_ASYNC,FromCache=INTERNET_FLAG_FROM_CACHE,
|
||||
Offline=INTERNET_FLAG_OFFLINE,InvalidPort=INTERNET_INVALID_PORT_NUMBER,None=0};
|
||||
Internet();
|
||||
virtual ~Internet();
|
||||
bool open(AccessType accessType=NoAutoProxy,const String &strProxyServer=String(),const String &proxyBypass=String(),Flags flags=None,const String &agent="Microsoft Internet Explorer");
|
||||
bool open(const String &strProxyServer,const String &agent="Microsoft Internet Explorer");
|
||||
bool connect();
|
||||
void close();
|
||||
bool isOkay(void)const;
|
||||
HINTERNET getHANDLE(void)const;
|
||||
static String getProxyServer(void);
|
||||
private:
|
||||
HINTERNET mhInternet;
|
||||
};
|
||||
|
||||
inline
|
||||
Internet::Internet()
|
||||
: mhInternet(0)
|
||||
{
|
||||
}
|
||||
|
||||
inline
|
||||
Internet::~Internet()
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
inline
|
||||
bool Internet::open(AccessType accessType,const String &strProxyServer,const String &proxyByPass,Flags flags,const String &agent)
|
||||
{
|
||||
close();
|
||||
mhInternet=::InternetOpen(agent.str(),accessType,strProxyServer.str(),proxyByPass.str(),flags);
|
||||
return isOkay();
|
||||
}
|
||||
|
||||
inline
|
||||
bool Internet::open(const String &strProxyServer,const String &agent)
|
||||
{
|
||||
close();
|
||||
mhInternet=::InternetOpen(agent.str(),Proxy,strProxyServer.str(),0,None);
|
||||
return isOkay();
|
||||
}
|
||||
|
||||
|
||||
inline
|
||||
void Internet::close()
|
||||
{
|
||||
if(!isOkay())return;
|
||||
::InternetCloseHandle(mhInternet);
|
||||
mhInternet=0;
|
||||
}
|
||||
|
||||
inline
|
||||
HINTERNET Internet::getHANDLE(void)const
|
||||
{
|
||||
return mhInternet;
|
||||
}
|
||||
|
||||
inline
|
||||
bool Internet::isOkay()const
|
||||
{
|
||||
return mhInternet?true:false;
|
||||
}
|
||||
|
||||
inline
|
||||
String Internet::getProxyServer(void)
|
||||
{
|
||||
String strProxyServer;
|
||||
|
||||
RegKey regKey(RegKey::CurrentUser);
|
||||
if(!regKey.openKey("Comm\\Wininet"))return strProxyServer;
|
||||
if(!regKey.queryValue("ProxyServer",strProxyServer))return strProxyServer;
|
||||
return strProxyServer;
|
||||
}
|
||||
#endif
|
||||
81
wininet/InternetSettings.hpp
Normal file
81
wininet/InternetSettings.hpp
Normal file
@@ -0,0 +1,81 @@
|
||||
#ifndef _WININET_INTERNETSETTINGS_HPP_
|
||||
#define _WININET_INTERNETSETTINGS_HPP_
|
||||
#ifndef _COMMON_STRING_HPP_
|
||||
#include <common/string.hpp>
|
||||
#endif
|
||||
#ifndef _COMMON_REGKEY_HPP_
|
||||
#include <common/regkey.hpp>
|
||||
#endif
|
||||
|
||||
class InternetSettings
|
||||
{
|
||||
public:
|
||||
InternetSettings();
|
||||
virtual ~InternetSettings();
|
||||
bool getProxyEnable(void)const;
|
||||
const String &getUserAgent(void)const;
|
||||
const String &getAutoConfigProxy(void)const;
|
||||
const String &getProxyServer(void)const;
|
||||
const String &getAutoConfigURL(void)const;
|
||||
private:
|
||||
bool mProxyEnable;
|
||||
String mUserAgent;
|
||||
String mAutoConfigProxy;
|
||||
String mProxyServer;
|
||||
String mAutoConfigURL;
|
||||
};
|
||||
|
||||
inline
|
||||
InternetSettings::InternetSettings()
|
||||
{
|
||||
RegKey regKey(RegKey::CurrentUser);
|
||||
DWORD proxyEnable;
|
||||
|
||||
proxyEnable=0;
|
||||
if(!regKey.openKey("software\\microsoft\\windows\\currentversion\\Internet Settings"))return;
|
||||
regKey.queryValue("ProxyServer",mProxyServer);
|
||||
regKey.queryValue("User Agent",mUserAgent);
|
||||
regKey.queryValue("AutoConfigProxy",mAutoConfigProxy);
|
||||
regKey.queryValue("AutoConfigURL",mAutoConfigURL);
|
||||
regKey.queryValue("ProxyEnable",proxyEnable);
|
||||
mProxyEnable=proxyEnable?true:false;
|
||||
}
|
||||
|
||||
inline
|
||||
InternetSettings::~InternetSettings()
|
||||
{
|
||||
}
|
||||
|
||||
inline
|
||||
bool InternetSettings::getProxyEnable(void)const
|
||||
{
|
||||
return mProxyEnable;
|
||||
}
|
||||
|
||||
inline
|
||||
const String &InternetSettings::getUserAgent(void)const
|
||||
{
|
||||
return mUserAgent;
|
||||
}
|
||||
|
||||
inline
|
||||
const String &InternetSettings::getAutoConfigProxy(void)const
|
||||
{
|
||||
return mAutoConfigProxy;
|
||||
}
|
||||
|
||||
inline
|
||||
const String &InternetSettings::getProxyServer(void)const
|
||||
{
|
||||
return mProxyServer;
|
||||
}
|
||||
|
||||
inline
|
||||
const String &InternetSettings::getAutoConfigURL(void)const
|
||||
{
|
||||
return mAutoConfigURL;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
14
wininet/Serializeable.hpp
Normal file
14
wininet/Serializeable.hpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef _WININET_SERIALIZEABLE_HPP_
|
||||
#define _WININET_SERIALIZEABLE_HPP_
|
||||
#ifndef _COMMON_STRING_HPP_
|
||||
#include <common/string.hpp>
|
||||
#endif
|
||||
|
||||
class Serializeable
|
||||
{
|
||||
public:
|
||||
protected:
|
||||
virtual String serialize(void)=0;
|
||||
private:
|
||||
};
|
||||
#endif
|
||||
82
wininet/connection.hpp
Normal file
82
wininet/connection.hpp
Normal file
@@ -0,0 +1,82 @@
|
||||
#ifndef _WININET_CONNECTION_HPP_
|
||||
#define _WININET_CONNECTION_HPP_
|
||||
#ifndef _WININET_INTERNET_HPP_
|
||||
#include <wininet/internet.hpp>
|
||||
#endif
|
||||
|
||||
class Connection
|
||||
{
|
||||
public:
|
||||
Connection();
|
||||
virtual ~Connection();
|
||||
bool connect(const Internet &internet,const String &strServer);
|
||||
bool connect(const Internet &internet,const String &strServer,int service,int port);
|
||||
bool connectURL(const Internet &internet,const String &strURL);
|
||||
void close();
|
||||
HINTERNET getHANDLE(void)const;
|
||||
bool isOkay(void)const;
|
||||
private:
|
||||
HINTERNET mhConnection;
|
||||
};
|
||||
|
||||
inline
|
||||
Connection::Connection()
|
||||
: mhConnection(0)
|
||||
{
|
||||
}
|
||||
|
||||
inline
|
||||
Connection::~Connection()
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
inline
|
||||
bool Connection::connect(const Internet &internet,const String &strServer)
|
||||
{
|
||||
if(!internet.isOkay())return false;
|
||||
close();
|
||||
mhConnection=::InternetConnect(internet.getHANDLE(),strServer.str(),INTERNET_INVALID_PORT_NUMBER,NULL,NULL,INTERNET_SERVICE_HTTP,0,0);
|
||||
return isOkay();
|
||||
}
|
||||
|
||||
// connect(internet,"loocalhost",INTERNET_SERVICE_HTTP,INTERNET_DEFAULT_HTTP_PORT)
|
||||
|
||||
inline
|
||||
bool Connection::connect(const Internet &internet,const String &strServer,int service,int port)
|
||||
{
|
||||
if(!internet.isOkay())return false;
|
||||
close();
|
||||
mhConnection=::InternetConnect(internet.getHANDLE(),strServer.str(),port,NULL,NULL,service,0,0);
|
||||
return isOkay();
|
||||
}
|
||||
|
||||
inline
|
||||
bool Connection::connectURL(const Internet &internet,const String &strURL)
|
||||
{
|
||||
if(!internet.isOkay())return false;
|
||||
close();
|
||||
mhConnection=::InternetConnect(internet.getHANDLE(),strURL.str(),INTERNET_INVALID_PORT_NUMBER,NULL,NULL,INTERNET_SERVICE_URL,0,0);
|
||||
return isOkay();
|
||||
}
|
||||
|
||||
inline
|
||||
void Connection::close()
|
||||
{
|
||||
if(!isOkay())return;
|
||||
::InternetCloseHandle(mhConnection);
|
||||
mhConnection=0;
|
||||
}
|
||||
|
||||
inline
|
||||
HINTERNET Connection::getHANDLE(void)const
|
||||
{
|
||||
return mhConnection;
|
||||
}
|
||||
|
||||
inline
|
||||
bool Connection::isOkay()const
|
||||
{
|
||||
return mhConnection?true:false;
|
||||
}
|
||||
#endif
|
||||
112
wininet/main.cpp
Normal file
112
wininet/main.cpp
Normal file
@@ -0,0 +1,112 @@
|
||||
#include <common/windows.hpp>
|
||||
#include <common/file.hpp>
|
||||
#include <common/StringBuffer.hpp>
|
||||
#include <wininet/internet.hpp>
|
||||
#include <wininet/HTTPConnection.hpp>
|
||||
#include <wininet/HTTPHeader.hpp>
|
||||
#include <wininet/InternetSettings.hpp>
|
||||
//#include <uuencode/uuencode.hpp>
|
||||
#include <iostream.h>
|
||||
|
||||
bool handleLogin(const String &server);
|
||||
bool handleUpload(const String &server,const String &strPathFileName);
|
||||
|
||||
void main(int argc,char **argv)
|
||||
{
|
||||
String strHost("localhost");
|
||||
|
||||
if(!handleLogin(strHost))
|
||||
{
|
||||
::printf("Login failed\n");
|
||||
return;
|
||||
}
|
||||
::printf("Login succeeded!\n");
|
||||
if(!handleUpload(strHost,"d:\\boneyard\\proto\\raiders2.bmp"))return;
|
||||
// if(!handleUpload(strHost,"c:\\proxy.txt"))return;
|
||||
}
|
||||
|
||||
bool handleLogin(const String &strHost)
|
||||
{
|
||||
HTTPConnection httpConnection;
|
||||
HTTPHeader httpHeader;
|
||||
HTTPData httpData;
|
||||
InternetSettings internetSettings;
|
||||
Internet internet;
|
||||
String strResult;
|
||||
bool result;
|
||||
int index;
|
||||
|
||||
if(internetSettings.getProxyEnable())result=internet.open(internetSettings.getProxyServer(),internetSettings.getUserAgent());
|
||||
else result=internet.open();
|
||||
if(!result)return false;
|
||||
result=httpConnection.connect(internet,strHost);
|
||||
if(!result)return false;
|
||||
result=httpConnection.post("/UpLoad/servlet/UpLoadServlet?action=login&userid=sean&password=foo",httpHeader,httpData);
|
||||
if(!result||200!=httpHeader.getResponseCode())return false;
|
||||
strResult=httpData.toString();
|
||||
if(-1==(index=strResult.strpos("RESULT=")))return false;
|
||||
strResult=strResult.substr(index).betweenString('"','"');
|
||||
return strResult.toInt();
|
||||
}
|
||||
|
||||
bool handleUpload(const String &strHost,const String &strPathFileName)
|
||||
{
|
||||
HTTPConnection httpConnection;
|
||||
HTTPHeader httpHeader;
|
||||
HTTPData httpData;
|
||||
InternetSettings internetSettings;
|
||||
Internet internet;
|
||||
// UUEncode uuencode;
|
||||
String strRequest;
|
||||
String strResult;
|
||||
Array<BYTE> bytes;
|
||||
bool result;
|
||||
int index;
|
||||
|
||||
httpHeader.setContentType(ContentType::getContentType(ContentType::MultipartFormData));
|
||||
if(internetSettings.getProxyEnable())result=internet.open(internetSettings.getProxyServer(),internetSettings.getUserAgent());
|
||||
else result=internet.open();
|
||||
if(!result)return false;
|
||||
result=httpConnection.connect(internet,strHost);
|
||||
if(!result)return false;
|
||||
File inFile;
|
||||
if(!inFile.open(strPathFileName,"rb"))return false;
|
||||
strRequest="/UpLoad/servlet/UpLoadServlet?action=upload&data=";
|
||||
|
||||
inFile.seek(0,File::SeekEnd);
|
||||
bytes.size(inFile.tell());
|
||||
inFile.seek(0,File::SeekSet);
|
||||
inFile.read((void*)&bytes[0],bytes.size());
|
||||
inFile.close();
|
||||
// strRequest+=uuencode.encode(bytes);
|
||||
|
||||
OutputDebugString(strRequest+String("\n"));
|
||||
|
||||
|
||||
result=httpConnection.post(strRequest,httpHeader,httpData);
|
||||
if(!result||200!=httpHeader.getResponseCode())return false;
|
||||
strResult=httpData.toString();
|
||||
if(-1==(index=strResult.strpos("RESULT=")))return false;
|
||||
strResult=strResult.substr(index).betweenString('"','"');
|
||||
return strResult.toInt();
|
||||
}
|
||||
|
||||
/*
|
||||
File inFile;
|
||||
Array<BYTE> bytes;
|
||||
String strRequest;
|
||||
UUEncode uuencode;
|
||||
if(!inFile.open("c:\\proxy.txt","rb"))return;
|
||||
inFile.seek(0,File::SeekEnd);
|
||||
bytes.size(inFile.tell());
|
||||
inFile.seek(0,File::SeekSet);
|
||||
inFile.read((void*)&bytes[0],bytes.size());
|
||||
inFile.close();
|
||||
strRequest=uuencode.encode(bytes);
|
||||
File outFile;
|
||||
outFile.open("c:\\proxy.uue","wb");
|
||||
outFile.write(strRequest.str(),strRequest.length());
|
||||
|
||||
OutputDebugString(strRequest+String("\n"));
|
||||
|
||||
*/
|
||||
113
wininet/main.dsp
Normal file
113
wininet/main.dsp
Normal file
@@ -0,0 +1,113 @@
|
||||
# Microsoft Developer Studio Project File - Name="main" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||
|
||||
CFG=main - Win32 Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "main.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "main.mak" CFG="main - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "main - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE "main - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "main - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||
|
||||
!ELSEIF "$(CFG)" == "main - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "msvcobj"
|
||||
# PROP Intermediate_Dir "msvcobj"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /Gd /MDd /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "STRICT" /D "__FLAT__" /YX /FD /GZ /c
|
||||
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
||||
# ADD RSC /l 0x409 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib wininet.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "main - Win32 Release"
|
||||
# Name "main - Win32 Debug"
|
||||
# Begin Group "Source Files"
|
||||
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\HTTPConnection.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\HTTPData.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\HTTPHeader.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\main.cpp
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||
# End Group
|
||||
# Begin Group "Resource Files"
|
||||
|
||||
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||
# End Group
|
||||
# End Target
|
||||
# End Project
|
||||
44
wininet/main.dsw
Normal file
44
wininet/main.dsw
Normal file
@@ -0,0 +1,44 @@
|
||||
Microsoft Developer Studio Workspace File, Format Version 6.00
|
||||
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "common"=..\common\common.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "main"=.\main.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name common
|
||||
End Project Dependency
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Global:
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<3>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
BIN
wininet/main.opt
Normal file
BIN
wininet/main.opt
Normal file
Binary file not shown.
36
wininet/main.plg
Normal file
36
wininet/main.plg
Normal file
@@ -0,0 +1,36 @@
|
||||
<html>
|
||||
<body>
|
||||
<pre>
|
||||
<h1>Build Log</h1>
|
||||
<h3>
|
||||
--------------------Configuration: main - Win32 Debug--------------------
|
||||
</h3>
|
||||
<h3>Command Lines</h3>
|
||||
Creating temporary file "C:\WINNT\Profiles\sean\LOCALS~1\Temp\RSP2.tmp" with contents
|
||||
[
|
||||
/nologo /MDd /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "STRICT" /D "__FLAT__" /Fp"msvcobj/main.pch" /YX /Fo"msvcobj/" /Fd"msvcobj/" /FD /GZ /c
|
||||
"D:\work\wininet\main.cpp"
|
||||
]
|
||||
Creating command line "cl.exe @C:\WINNT\Profiles\sean\LOCALS~1\Temp\RSP2.tmp"
|
||||
Creating temporary file "C:\WINNT\Profiles\sean\LOCALS~1\Temp\RSP3.tmp" with contents
|
||||
[
|
||||
kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib wininet.lib /nologo /subsystem:console /incremental:yes /pdb:"msvcobj/main.pdb" /debug /machine:I386 /out:"msvcobj/main.exe" /pdbtype:sept
|
||||
.\msvcobj\HTTPConnection.obj
|
||||
.\msvcobj\HTTPData.obj
|
||||
.\msvcobj\HTTPHeader.obj
|
||||
.\msvcobj\main.obj
|
||||
\work\exe\mscommon.lib
|
||||
]
|
||||
Creating command line "link.exe @C:\WINNT\Profiles\sean\LOCALS~1\Temp\RSP3.tmp"
|
||||
<h3>Output Window</h3>
|
||||
Compiling...
|
||||
main.cpp
|
||||
Linking...
|
||||
|
||||
|
||||
|
||||
<h3>Results</h3>
|
||||
main.exe - 0 error(s), 0 warning(s)
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
||||
87
wininet/scraps.txt
Normal file
87
wininet/scraps.txt
Normal file
@@ -0,0 +1,87 @@
|
||||
bool HTTPConnection::get(const String &action,HTTPHeader &httpHeader,HTTPData &httpData)
|
||||
{
|
||||
DWORD dwSize(0);
|
||||
String strHeaders;
|
||||
// String strHeader;
|
||||
bool sendResult=false;
|
||||
|
||||
LPSTR accessTypes[2]={"*/*",0};
|
||||
if(!isOkay())return false;
|
||||
mhRequest=::HttpOpenRequest(getHANDLE(),"GET",action.str(),HTTP_VERSION,0,(const char**)&accessTypes,INTERNET_FLAG_RELOAD|INTERNET_FLAG_NO_CACHE_WRITE,0);
|
||||
if(!mhRequest)return false;
|
||||
// strHeader=httpHeader.serialize();
|
||||
if(!::HttpSendRequest(mhRequest,0,0,0,0))return false;
|
||||
// if(httpData.size()&&!strHeader.isNull())sendResult=::HttpSendRequest(mhRequest,strHeader.str(),strHeader.length(),&httpData[0],httpData.size());
|
||||
// else sendResult=::HttpSendRequest(mhRequest,0,0,0,0);
|
||||
// if(!sendResult)return false;
|
||||
::HttpQueryInfo(mhRequest,HTTP_QUERY_RAW_HEADERS_CRLF,0,&dwSize,0);
|
||||
if(!dwSize)return false;
|
||||
strHeaders.reserve(dwSize+1);
|
||||
::HttpQueryInfo(mhRequest,HTTP_QUERY_RAW_HEADERS_CRLF,strHeaders,&dwSize,0);
|
||||
httpHeader=strHeaders;
|
||||
if(httpHeader.isErrorResponse())return false;
|
||||
httpData.size(httpHeader.getContentLength());
|
||||
if(!httpData.size())httpData.size(32768);
|
||||
::InternetReadFile(mhRequest,&httpData[0],httpData.size(),&dwSize);
|
||||
if(dwSize<httpData.size())
|
||||
{
|
||||
HTTPData tmpData;
|
||||
tmpData.size(dwSize);
|
||||
for(int index=0;index<dwSize;index++)tmpData[index]=httpData[index];
|
||||
httpData=tmpData;
|
||||
}
|
||||
closeRequest();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
int main(int argc,char **argv)
|
||||
{
|
||||
Internet internet;
|
||||
HTTPConnection http;
|
||||
HTTPHeader httpHeader;
|
||||
HTTPData httpData;
|
||||
String strApplicationExtension;
|
||||
|
||||
|
||||
::OutputDebugString(Internet::getProxyServer()+String("\n"));
|
||||
if(!internet.open())return 0;
|
||||
|
||||
if(!http.connect(internet,"localhost"))return 0;
|
||||
// httpData="?mailid=10237";
|
||||
// http.get("mailclient/servlet/ReadMailServlet?mailid=10237",httpHeader,httpData);
|
||||
// http.get("diveplanner/aladinv1.00.zip",httpHeader,httpData);
|
||||
http.get("album/diving/divecayman/Cayman10_l.jpg",httpHeader,httpData);
|
||||
|
||||
strApplicationExtension=httpHeader.getApplicationExtension();
|
||||
// File outFile(String("c:\\mail")+strApplicationExtension,"wb");
|
||||
File outFile(String("c:\\mail.jpg"),"wb");
|
||||
|
||||
outFile.write(&httpData[0],httpData.size());
|
||||
outFile.close();
|
||||
::OutputDebugString("Connected.");
|
||||
return 1;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
// File outFile("c:\\mail.txt","wb");
|
||||
// outFile.write(&httpData[0],httpData.size());
|
||||
// http.post("mailclient/servlet/ReadMailServlet",formHeader,httpData);
|
||||
// formHeader.setContentType("application/x-www-form-urlencoded");
|
||||
// httpData="?mailid=10237";
|
||||
// http.post("mailclient/servlet/ReadMailServlet",formHeader,httpData);
|
||||
// ::OutputDebugString(httpData);
|
||||
|
||||
|
||||
// if(!http.getPage("//album//index.html",httpHeader,pageData))return 0;
|
||||
// if(!http.get("//engineer//engineer.zip",httpHeader,httpData))return 0;
|
||||
// File outFile("c:\\engineer.zip","wb");
|
||||
// outFile.write(&httpData[0],httpData.size());
|
||||
|
||||
|
||||
|
||||
104
wininet/wininet.dsp
Normal file
104
wininet/wininet.dsp
Normal file
@@ -0,0 +1,104 @@
|
||||
# Microsoft Developer Studio Project File - Name="wininet" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Static Library" 0x0104
|
||||
|
||||
CFG=wininet - Win32 Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "wininet.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "wininet.mak" CFG="wininet - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "wininet - Win32 Release" (based on "Win32 (x86) Static Library")
|
||||
!MESSAGE "wininet - Win32 Debug" (based on "Win32 (x86) Static Library")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "wininet - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
|
||||
# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE LIB32 /nologo
|
||||
# ADD LIB32 /nologo
|
||||
|
||||
!ELSEIF "$(CFG)" == "wininet - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "wininet___Win32_Debug"
|
||||
# PROP BASE Intermediate_Dir "wininet___Win32_Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "msvcobj"
|
||||
# PROP Intermediate_Dir "msvcobj"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /Gz /MDd /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /D "STRICT" /D "__FLAT__" /YX"windows.h" /FD /GZ /c
|
||||
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
||||
# ADD RSC /l 0x409 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE LIB32 /nologo
|
||||
# ADD LIB32 /nologo /out:"..\exe\wininet.lib"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "wininet - Win32 Release"
|
||||
# Name "wininet - Win32 Debug"
|
||||
# Begin Group "Source Files"
|
||||
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\HTTPConnection.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\HTTPData.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\HTTPHeader.cpp
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||
# End Group
|
||||
# End Target
|
||||
# End Project
|
||||
44
wininet/wininet.dsw
Normal file
44
wininet/wininet.dsw
Normal file
@@ -0,0 +1,44 @@
|
||||
Microsoft Developer Studio Workspace File, Format Version 6.00
|
||||
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "common"=..\common\common.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "wininet"=.\wininet.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name common
|
||||
End Project Dependency
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Global:
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<3>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
BIN
wininet/wininet.opt
Normal file
BIN
wininet/wininet.opt
Normal file
Binary file not shown.
29
wininet/wininet.plg
Normal file
29
wininet/wininet.plg
Normal file
@@ -0,0 +1,29 @@
|
||||
<html>
|
||||
<body>
|
||||
<pre>
|
||||
<h1>Build Log</h1>
|
||||
<h3>
|
||||
--------------------Configuration: wininet - Win32 Debug--------------------
|
||||
</h3>
|
||||
<h3>Command Lines</h3>
|
||||
Creating temporary file "C:\WINNT\Profiles\sean\LOCALS~1\Temp\RSP48.tmp" with contents
|
||||
[
|
||||
/nologo /Gr /MDd /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /D "STRICT" /D "__FLAT__" /Fp"msvcobj/wininet.pch" /YX"windows.h" /Fo"msvcobj/" /Fd"msvcobj/" /FD /GZ /c
|
||||
"D:\work\wininet\HTTPConnection.cpp"
|
||||
"D:\work\wininet\HTTPHeader.cpp"
|
||||
]
|
||||
Creating command line "cl.exe @C:\WINNT\Profiles\sean\LOCALS~1\Temp\RSP48.tmp"
|
||||
Creating command line "link.exe -lib /nologo /out:"..\exe\wininet.lib" .\msvcobj\HTTPConnection.obj .\msvcobj\HTTPHeader.obj \work\exe\mscommon.lib "
|
||||
<h3>Output Window</h3>
|
||||
Compiling...
|
||||
HTTPConnection.cpp
|
||||
HTTPHeader.cpp
|
||||
Creating library...
|
||||
|
||||
|
||||
|
||||
<h3>Results</h3>
|
||||
wininet.lib - 0 error(s), 0 warning(s)
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user