113 lines
3.3 KiB
C++
113 lines
3.3 KiB
C++
#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"));
|
|
|
|
*/
|