本文整理汇总了C++中InternetOpen函数的典型用法代码示例。如果您正苦于以下问题:C++ InternetOpen函数的具体用法?C++ InternetOpen怎么用?C++ InternetOpen使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了InternetOpen函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: baidu_upload
BOOL baidu_upload(CString sfile, CString token, CString fname,DWORD *process)
{
if (sfile == L"")
{
MessageBox(NULL, L"Îļþ·¾¶²»ÄÜΪ¿Õ", 0, 0);
return FALSE;
}
if (token == L"")
{
MessageBox(NULL, L"token²»ÄÜΪ¿Õ", 0, 0);
return FALSE;
}
if (fname == L"")
{
MessageBox(NULL, L"ÎļþÃû²»ÄÜΪ¿Õ", 0, 0);
return FALSE;
}
CString url(L"/rest/2.0/pcs/file?method=upload&ondup=overwrite&path=%2Fapps%2Fhitdisk%2F" + fname + L"&access_token=" + token);
DWORD total_length = 0;//ÉÏ´«Êý¾Ý×Ü´óС
DWORD file_length = 0;//ÉÏ´«ÎļþµÄ´óС
//DWORD read_length = 0;//ÒѾ´ÓÎļþ¶ÁÈ¡µÄ´óС
DWORD sent_length = 0;//ÒѾÉÏ´«µÄÎļþµÄ´óС
DWORD sent_bfleng = 0;//µ±Ç°Êý¾Ý¿éÒÑÉÏ´«´óС
DWORD head_length = 0;//Êý¾ÝÍ·´óС
DWORD tail_length = 0;//Êý¾Ýβ´óС
DWORD read_part = 1024 * 1024 * 2;
DWORD send_part = 1024;
DWORD read_tmp = 0;//µ±Ç°´ÓÎļþ¶ÁÈ¡µ½»º³åÇøµÄ´óС
DWORD sent_tmp = 0;//µ±Ç°·¢ËÍ´óС
CFile cfile(sfile, CFile::modeRead);
file_length = (DWORD)cfile.GetLength();
CHAR *send_buffer = new CHAR[read_part];
HINTERNET hRequest = NULL;
HINTERNET hConnect = NULL;
HINTERNET hnet = InternetOpen(fname, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
hConnect = InternetConnect(hnet, L"pcs.baidu.com", 443, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
hRequest = HttpOpenRequest(hConnect, L"POST", url, NULL, NULL, NULL, INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP | INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_NO_AUTH | INTERNET_FLAG_NO_COOKIES | INTERNET_FLAG_NO_UI | INTERNET_FLAG_SECURE | INTERNET_FLAG_IGNORE_CERT_CN_INVALID | INTERNET_FLAG_RELOAD, 0);
TCHAR ct[] = L"Content-Type: multipart/form-data; boundary=--myself";
HttpAddRequestHeaders(hRequest, ct, lstrlen(ct), HTTP_ADDREQ_FLAG_ADD | HTTP_ADDREQ_FLAG_REPLACE);
CHAR head[] = "----myself\r\nContent-Disposition: form-data; name=\"file\"; filename=\"\"\r\n\r\n";
CHAR tail[] = "\r\n----myself--\r\n";
head_length = strlen(head);
tail_length = strlen(tail);
total_length = file_length + head_length + tail_length;
INTERNET_BUFFERS Ibuffer;
ZeroMemory(&Ibuffer, sizeof(INTERNET_BUFFERS));
Ibuffer.dwBufferTotal = total_length;
Ibuffer.dwStructSize = sizeof(INTERNET_BUFFERS);
HttpSendRequestEx(hRequest, &Ibuffer, NULL, 0, NULL);
InternetWriteFile(hRequest, head, head_length, &sent_tmp);
sent_length += sent_tmp;
while (read_tmp = cfile.Read(send_buffer, read_part))
{
sent_bfleng = 0;
while (sent_bfleng != read_tmp)
{
if (read_tmp - sent_bfleng > send_part)
{
InternetWriteFile(hRequest, send_buffer + sent_bfleng, send_part, &sent_tmp);
}
else
{
InternetWriteFile(hRequest, send_buffer + sent_bfleng, read_tmp - sent_bfleng, &sent_tmp);
}
if (sent_tmp == 0)
{
InternetCloseHandle(hRequest);
InternetCloseHandle(hConnect);
InternetCloseHandle(hnet);
cfile.Close();
delete[] send_buffer;
return FALSE;
}
sent_bfleng += sent_tmp;
sent_length += sent_tmp;
*process = (DWORD)(100 * (double)sent_length / total_length);
}
}
//.........这里部分代码省略.........
示例2: LoadLibrary
bool CFileDownloader::backgroundMultiDownLoadFile( wstring url )
{
HMODULE hDll;
LPVOID hInternet, hUrlHandle;
TCHAR buf[100];
DWORD dwSize;
// 动态加载dll,此DLL为系统自带,这样做为以后缩减执行程序体积做准备
hDll = LoadLibrary(_T("wininet.dll"));
// 读取DLL失败,返回false
if (!hDll)
{
return false;
}
// 为DLL内的函数定义
typedef LPVOID(WINAPI *pInternetOpen) (LPCTSTR, DWORD, LPCTSTR, LPCTSTR, DWORD);
typedef LPVOID(WINAPI *pInternetOpenUrl) (LPVOID, LPCTSTR, LPCTSTR, DWORD, DWORD, DWORD);
typedef BOOL(WINAPI *pInternetCloseHandle) (LPVOID);
typedef BOOL(WINAPI *pInternetReadFile) (LPVOID ,LPVOID ,DWORD ,LPDWORD);
pInternetOpen InternetOpen = NULL;
pInternetOpenUrl InternetOpenURL = NULL;
pInternetCloseHandle InternetCloseHandle = NULL;
pInternetReadFile InternetReadFile = NULL;
InternetOpen = (pInternetOpen) GetProcAddress(hDll, "InternetOpenW");
InternetOpenURL = (pInternetOpenUrl) GetProcAddress(hDll, "InternetOpenUrlW");
InternetCloseHandle = (pInternetCloseHandle) GetProcAddress(hDll, "InternetCloseHandle");
InternetReadFile = (pInternetReadFile) GetProcAddress(hDll, "InternetReadFile");
hInternet = InternetOpen(_T("Downloader"), 0, NULL, NULL, 0);
// 建立网络连接失败
if (hInternet == NULL)
{
return false;
}
// 采用无缓冲的传输
hUrlHandle = InternetOpenURL(hInternet, url.c_str(), NULL, 0, 0x04000000, 0);
// 打开URL失败
if (hUrlHandle == NULL)
{
return false;
}
wmemset(buf, 0, 100);
// 先读取一个8字节的文件头
InternetReadFile(hUrlHandle, buf, 8, &dwSize);
// 读取接下来的索引文件
wstring str;
do
{
wmemset(buf, 0, 100);
// 读取失败则停止读取
if (!InternetReadFile(hUrlHandle, buf, 100, &dwSize))
{
break;
}
str.append(buf);
if (dwSize < 100)
{
break;
}
}
while(true);
// 解析索引文件
wstring::size_type pos = wstring::npos;
do
{
// 将|作为不同Url的分隔符
pos = str.find_first_of(_T('|'));
if (pos != wstring::npos)
{
// 未解析的字符串中的第一段URL
wstring::size_type pos = str.find_first_of(_T('|'));
wstring curFileUrl = str.substr(0, pos);
downloadExec(curFileUrl.c_str());
// 去掉已经解析的URL
if (str.length() > pos + 1)
{
str = str.substr(pos + 1, wstring::npos);
}
else
{
break;
}
}
//.........这里部分代码省略.........
示例3: GetFBStatuses
FbStatus GetFBStatuses(string paramId, string paramField,string paramToken)
{
HINTERNET hopen, hconnect, hrequest;
string accesstoken = paramToken;
int n = accesstoken.size();
string version = "/v2.1";
string id = paramId;
string edge ="/statuses";
string field = paramField;
char chUrlRequset [400];
FbStatus t;
string urlRequest = version+id+edge+field+"&"+accesstoken;
String2Char(urlRequest,chUrlRequset);
hopen = InternetOpen("HTTPGET",INTERNET_OPEN_TYPE_DIRECT,NULL,NULL,0);
hconnect = InternetConnect(hopen,GRAPH_FB,INTERNET_DEFAULT_HTTPS_PORT,NULL,NULL,INTERNET_SERVICE_HTTP,0,0);
//hrequest= HttpOpenRequestA(hconnect,"GET","/v2.1/me/statuses?fields=message&limit=2&access_token=CAAVUMKQz7ZB0BANtlRFjMPvzH2PQ2We0Xy6tyd8iAAnSMMHZCduQHQMGZAln4PWOQO6CPFnYT4LVpQJ2TBay7vIR268fuq3jVONE5Hteq05GQA8QlBapz3ZAWmQdmu43giQytttLwpCAphqZCcztAwrlLX3kpc2hm4tBCYmTn7xkRHPoEazE1Nb2XSXQAnYDRZCK6sNixcj7nDni2QN4am" ,"HTTP/1.1",NULL, NULL,INTERNET_FLAG_SECURE , 0);
hrequest= HttpOpenRequest(hconnect,"GET",chUrlRequset,"HTTP/1.1",NULL, NULL,INTERNET_FLAG_SECURE , 0);
printf("FB Sending\n");
if(HttpSendRequest(hrequest,NULL,NULL,NULL,0)){
printf("FB Success\n");
CHAR szBuffer[2048];
DWORD dwRead=0;
printf("FB Reading status\n");
while(InternetReadFile(hrequest, szBuffer, sizeof(szBuffer)-1, &dwRead) && dwRead)
{
szBuffer[dwRead] = 0;
//printf(szBuffer);
dwRead=0;
}
printf("FB Finish Reading\n");
cJSON *root = cJSON_Parse(szBuffer);
cJSON* arr = cJSON_GetObjectItem(root,"data");
//printf("\n\n");
if(cJSON_GetArraySize(arr)>0)
{
cJSON *subitem = cJSON_GetArrayItem(arr,0);
//printf("%s\n",cJSON_GetObjectItem(subitem,"message")->valuestring);
t.message = cJSON_GetObjectItem(subitem,"message")->valuestring;
t.Id = cJSON_GetObjectItem(subitem,"id")->valuestring;
printf("FB returning message\n");
return t;
}
}
else
{
printf("Failed\n");
return t;
}
//InternetCloseHandle(hrequest);
//InternetCloseHandle(hconnect);
//InternetCloseHandle(hopen);
}
示例4: Start
/*
* Initiates the HTTP tunnel and gets the ball rolling
*/
DWORD HttpTunnel::Start(
IN LPSTR InHttpHost,
IN USHORT InHttpPort)
{
DWORD ThreadId;
DWORD Result = ERROR_SUCCESS;
do
{
// Initialize the hostname and port
if (!(HttpHost = strdup(InHttpHost)))
{
Result = ERROR_NOT_ENOUGH_MEMORY;
break;
}
HttpPort = InHttpPort;
// Acquire the internet context handle
if (!(InternetHandle = InternetOpen(
NULL,
INTERNET_OPEN_TYPE_PRECONFIG,
NULL,
NULL,
0)))
{
Result = GetLastError();
break;
}
// Create the local TCP abstraction
if ((Result = InitializeLocalConnection()) != ERROR_SUCCESS)
{
CPassiveX::Log(
TEXT("Start(): InitializeLocalConnection failed, %lu.\n"),
Result);
break;
}
// Download the second stage if there is one
DownloadSecondStage();
// Create the transmission thread
if (!(SendThread = CreateThread(
NULL,
0,
(LPTHREAD_START_ROUTINE)SendThreadFuncSt,
this,
0,
&ThreadId)))
{
Result = GetLastError();
break;
}
// Create the receive thread
if (!(ReceiveThread = CreateThread(
NULL,
0,
(LPTHREAD_START_ROUTINE)ReceiveThreadFuncSt,
this,
0,
&ThreadId)))
{
Result = GetLastError();
break;
}
// Woop
Result = ERROR_SUCCESS;
} while (0);
return Result;
}
示例5: UploadLog
inline char UploadLog(unsigned long int no)
{
/* this function will transfer the log
files one by one to the FTP server */
static BOOL semaphore = FALSE;
if(semaphore == TRUE)
return 0;
else
semaphore = TRUE;
if(InternetCheckConnection(InternetCheckMask,FLAG_ICC_FORCE_CONNECTION,0))
{
/* connect me to the internet */
HINTERNET hNet = InternetOpen(AppName2, PRE_CONFIG_INTERNET_ACCESS,
NULL, INTERNET_INVALID_PORT_NUMBER, 0 );
if(hNet != NULL)
{
/* connect me to the remote FTP Server */
HINTERNET hFtp = InternetConnect(hNet,FtpServer,
INTERNET_DEFAULT_FTP_PORT,FtpUserName,FtpPassword,
INTERNET_SERVICE_FTP, 0, 0);
if(hFtp != NULL)
{
/* successful connection to FTP server established */
char local_file[MAX_PATH], remote_file[MAX_PATH];
sprintf(local_file,"%s%lX%s",BaseDirectory,no,STRING_LOGEXT);
sprintf(remote_file,"%lu-%lX%s",GetCompId(hFtp),no,STRING_SRVEXT);
//MessageBox(NULL,local_file,remote_file,0);
if(FtpPutFile(hFtp, local_file, remote_file, 0, 0))
{
/* file transfer OK */
InternetCloseHandle(hFtp);
InternetCloseHandle(hNet);
semaphore = FALSE;
return 1;
}
else {
/* file transfer failed */
InternetCloseHandle(hFtp);
InternetCloseHandle(hNet);
semaphore = FALSE;
return 0;
}
}
else {
/* connection to FTP server failed */
InternetCloseHandle(hNet);
semaphore = FALSE;
return 0;
}
}
else {
/* connection to internet failed */
semaphore = FALSE;
return 0;
}
}
/* internet connection is not available
either because the person is not online
or because a firewall has blocked me */
semaphore = FALSE;
return 0;
}
示例6: CheckVersion
void CheckVersion(void* dummy)
{
HINTERNET hRootHandle = InternetOpen(
L"Rainmeter",
INTERNET_OPEN_TYPE_PRECONFIG,
nullptr,
nullptr,
0);
if (hRootHandle == nullptr)
{
return;
}
HINTERNET hUrlDump = InternetOpenUrl(
hRootHandle, L"http://rainmeter.github.io/rainmeter/release", nullptr, 0, INTERNET_FLAG_RESYNCHRONIZE, 0);
if (hUrlDump)
{
DWORD dwSize;
char urlData[16] = {0};
if (InternetReadFile(hUrlDump, (LPVOID)urlData, sizeof(urlData) - 1, &dwSize))
{
auto parseVersion = [](const WCHAR* str)->int
{
int version = _wtoi(str) * 1000000;
const WCHAR* pos = wcschr(str, L'.');
if (pos)
{
++pos; // Skip .
version += _wtoi(pos) * 1000;
pos = wcschr(pos, '.');
if (pos)
{
++pos; // Skip .
version += _wtoi(pos);
}
}
return version;
};
std::wstring tmpSz = StringUtil::Widen(urlData);
const WCHAR* version = tmpSz.c_str();
int availableVersion = parseVersion(version);
if (availableVersion > RAINMETER_VERSION ||
(revision_beta && availableVersion == RAINMETER_VERSION))
{
GetRainmeter().SetNewVersion();
WCHAR buffer[32];
const WCHAR* dataFile = GetRainmeter().GetDataFile().c_str();
GetPrivateProfileString(L"Rainmeter", L"LastCheck", L"0", buffer, _countof(buffer), dataFile);
// Show tray notification only once per new version
int lastVersion = parseVersion(buffer);
if (availableVersion > lastVersion)
{
GetRainmeter().GetTrayIcon()->ShowUpdateNotification(version);
WritePrivateProfileString(L"Rainmeter", L"LastCheck", version, dataFile);
}
}
}
InternetCloseHandle(hUrlDump);
}
InternetCloseHandle(hRootHandle);
}
示例7: check_crashdump
/* Crashdumps handling */
static void check_crashdump(void)
{
FILE * fd = _wfopen ( crashdump_path, L"r, ccs=UTF-8" );
if( !fd )
return;
fclose( fd );
int answer = MessageBox( NULL, L"Ooops: VLC media player just crashed.\n" \
"Would you like to send a bug report to the developers team?",
L"VLC crash reporting", MB_YESNO);
if(answer == IDYES)
{
HINTERNET Hint = InternetOpen(L"VLC Crash Reporter",
INTERNET_OPEN_TYPE_PRECONFIG, NULL,NULL,0);
if(Hint)
{
HINTERNET ftp = InternetConnect(Hint, L"crash.videolan.org",
INTERNET_DEFAULT_FTP_PORT, NULL, NULL,
INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
if(ftp)
{
SYSTEMTIME now;
GetSystemTime(&now);
wchar_t remote_file[MAX_PATH];
_snwprintf(remote_file, MAX_PATH,
L"/crashes-win32/%04d%02d%02d%02d%02d%02d",
now.wYear, now.wMonth, now.wDay, now.wHour,
now.wMinute, now.wSecond );
if( FtpPutFile( ftp, crashdump_path, remote_file,
FTP_TRANSFER_TYPE_BINARY, 0) )
MessageBox( NULL, L"Report sent correctly. Thanks a lot " \
"for the help.", L"Report sent", MB_OK);
else
MessageBox( NULL, L"There was an error while "\
"transferring the data to the FTP server.\n"\
"Thanks a lot for the help.",
L"Report sending failed", MB_OK);
InternetCloseHandle(ftp);
}
else
{
MessageBox( NULL, L"There was an error while connecting to " \
"the FTP server. "\
"Thanks a lot for the help.",
L"Report sending failed", MB_OK);
fprintf(stderr,"Can't connect to FTP server 0x%08lu\n",
(unsigned long)GetLastError());
}
InternetCloseHandle(Hint);
}
else
{
MessageBox( NULL, L"There was an error while connecting to the Internet.\n"\
"Thanks a lot for the help anyway.",
L"Report sending failed", MB_OK);
}
}
_wremove(crashdump_path);
}
示例8: download_simple
/* return value:
* 0 success
* -1 fopen failed
* -2 curl initialization failed
* -3 scheme is neither http nor https
* -4 faild to parse the URL (InternetCrackUrl) (windows)
* -5 https responce status is not HTTP_STATUS_OK (windows)
* -6 HttpQueryInfo failed (windows)
* -7 rename failure
*/
int download_simple (char* uri,char* path,int opt) {
FILE *bodyfile;
char* path_partial=cat(path,".partial",NULL);
bodyfile = fopen(path_partial,"wb");
if (bodyfile == NULL) {
s(path_partial);
return -1;
}
c_out=0==(download_opt=opt)?stderr:stdout;
#ifndef HAVE_WINDOWS_H
CURL *curl;
CURLcode res=!CURLE_OK;
curl = curl_easy_init();
if(curl) {
char* current=get_opt("ros.proxy",1);
if(current) {
/*<[protocol://][user:[email protected]]proxyhost[:port]>*/
char *reserve=current,*protocol=NULL,*userpwd=NULL,*port=NULL,*uri=NULL;
int pos=position_char("/",current);
if(pos>0 && current[pos-1]==':' && current[pos+1]=='/')
protocol=current,current[pos-1]='\0',current=current+pos+2;
pos=position_char("@",current);
if(pos!=-1)
userpwd=current,current[pos]='\0',current=current+pos+1;
pos=position_char(":",current);
if(pos!=-1)
current[pos]='\0',port=current+pos+1,uri=current;
curl_easy_setopt(curl, CURLOPT_PROXY, uri);
if(port)
curl_easy_setopt(curl, CURLOPT_PROXYPORT,atoi(port));
if(userpwd)
curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, userpwd);
s(reserve);
}
count=0,content_length=0;
curl_easy_setopt(curl, CURLOPT_URL, uri);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, header_callback);
curl_easy_setopt(curl,CURLOPT_WRITEDATA,bodyfile);
res = curl_easy_perform(curl);
if(res != CURLE_OK && verbose) {
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
}
curl_easy_cleanup(curl);
fclose(bodyfile);
}
if(res != CURLE_OK)
return -2;
#else
URL_COMPONENTS u;
TCHAR szHostName[4096];
TCHAR szUrlPath[4096];
u.dwStructSize = sizeof(u);
u.dwSchemeLength = 1;
u.dwHostNameLength = 4096;
u.dwUserNameLength = 1;
u.dwPasswordLength = 1;
u.dwUrlPathLength = 4096;
u.dwExtraInfoLength = 1;
u.lpszScheme = NULL;
u.lpszHostName = szHostName;
u.lpszUserName = NULL;
u.lpszPassword = NULL;
u.lpszUrlPath = szUrlPath;
u.lpszExtraInfo = NULL;
if(!InternetCrackUrl(uri,(DWORD)strlen(uri),0,&u)) {
fclose(bodyfile);
return -4;
}
HINTERNET hSession = InternetOpen("WinInet",INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
HINTERNET hConnection = InternetConnect(hSession,szHostName,u.nPort,NULL,NULL,INTERNET_SERVICE_HTTP,0,0);
DWORD dwFlags = INTERNET_FLAG_RELOAD | INTERNET_FLAG_DONT_CACHE;
if(INTERNET_SCHEME_HTTP == u.nScheme) {
}else if( INTERNET_SCHEME_HTTPS == u.nScheme ) {
dwFlags = dwFlags | INTERNET_FLAG_SECURE| INTERNET_FLAG_IGNORE_CERT_DATE_INVALID| INTERNET_FLAG_IGNORE_CERT_CN_INVALID;
}else {
fclose(bodyfile);
return -3;
}
HINTERNET hRequest = HttpOpenRequest(hConnection,"GET",szUrlPath,NULL,NULL,NULL,dwFlags,0);
HttpSendRequest(hRequest,NULL,0,NULL,0);
DWORD dwStatusCode,dwContentLen;
DWORD dwLength = sizeof(DWORD);
if(HttpQueryInfo(hRequest,HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER,&dwContentLen,&dwLength,0))
content_length=dwContentLen;
//.........这里部分代码省略.........
示例9: bSuccess
bool CHttpClient::Request(const TCHAR * pURL)
{
bool bSuccess(false);
if (pURL != NULL) {
URL_COMPONENTS urlCom = {sizeof(URL_COMPONENTS),
NULL, 1, INTERNET_SCHEME_DEFAULT,
NULL, 1, 0,
NULL, 1,
NULL, 1,
NULL, 1,
NULL, 1,
};
InternetCrackUrl(pURL, lstrlen(pURL), 0, &urlCom);
mServer = urlCom.lpszHostName ? lstring(urlCom.lpszHostName, urlCom.dwHostNameLength) : pURL;
mPort = urlCom.nPort;
if (urlCom.lpszUrlPath)
mPath = lstring(urlCom.lpszUrlPath, urlCom.dwUrlPathLength);
if (urlCom.lpszUserName)
mUserName = lstring(urlCom.lpszUserName, urlCom.dwUserNameLength);
if (urlCom.lpszPassword)
mPassword = lstring(urlCom.lpszPassword, urlCom.dwPasswordLength);
SetHttps(urlCom.nScheme == INTERNET_SCHEME_HTTPS);
}
HINTERNET hi = InternetOpen(mUserAgent.c_str(), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
if (hi != NULL) {
if (!mPort)
mPort = IsHttps() ? INTERNET_DEFAULT_HTTPS_PORT : INTERNET_DEFAULT_HTTP_PORT;
HINTERNET hc = InternetConnect(hi, mServer.c_str(), mPort,
GET_PTR_FROM_STR(mUserName), GET_PTR_FROM_STR(mPassword),
INTERNET_SERVICE_HTTP, 0, 0);
if (hc != NULL) {
const TCHAR *rgpszAcceptTypes[] = { _T("*/*"), NULL};
DWORD dwDword(INTERNET_FLAG_NO_UI);
if (IsHttps())
dwDword |= INTERNET_FLAG_SECURE;
HINTERNET http = HttpOpenRequest(hc, GET_PTR_FROM_STR(mhttpVerb), mPath.c_str(), NULL, NULL, rgpszAcceptTypes,
dwDword, NULL);
if (http != NULL) {
if (HttpSendRequest(http, GET_PTR_FROM_STR(mhttpHeaders), (DWORD)mhttpHeaders.length(), mDataToSend, (DWORD)mDataToSend.DataSize())) {
int statusCode(0);
{
wchar_t responseText[1024]; // change to wchar_t for unicode
DWORD responseTextSize = sizeof(responseText);
//Check existence of page (for 404 error)
if (!HttpQueryInfo(http,
HTTP_QUERY_STATUS_CODE,
&responseText,
&responseTextSize,
NULL))
statusCode = GetLastError();
else
STLUtils::ChangeType(lstring(responseText), statusCode);
}
BinaryData inDataRead(NULL, 1024*1024*4); // 4MB
while (InternetReadFile(http, inDataRead, (DWORD)inDataRead.Size(), &dwDword) && dwDword > 0)
{
bSuccess = true;
inDataRead.SetDataSize(dwDword);
if (!ContentHandler(inDataRead))
break;
}
}
InternetCloseHandle(http);
}
InternetCloseHandle(hc);
}
InternetCloseHandle(hi);
}
return bSuccess;
}
示例10: uploadFile
// Uploads the PNG file to Gyazo
BOOL uploadFile(HWND hwnd, LPCTSTR fileName, BOOL isPng)
{
const int nSize = 256;
LPCTSTR DEFAULT_UPLOAD_SERVER = _T("upload.gyazo.com");
LPCTSTR DEFAULT_UPLOAD_PATH = _T("/upload.cgi");
LPCTSTR DEFAULT_UPLOAD_TOKEN = _T("");
//LPCTSTR DEFAULT_USER_AGENT = _T("User-Agent: Gyazowin/1.0\r\n");
const int DEFAULT_UPLOAD_SERVER_PORT = INTERNET_DEFAULT_HTTP_PORT;
TCHAR upload_server[nSize];
TCHAR upload_path[nSize];
TCHAR upload_token[nSize];
//TCHAR ua[nSize];
lstrcpy(upload_server, DEFAULT_UPLOAD_SERVER);
lstrcpy(upload_path, DEFAULT_UPLOAD_PATH);
lstrcpy(upload_token, DEFAULT_UPLOAD_TOKEN);
//lstrcpy(ua, DEFAULT_USER_AGENT);
int upload_server_port = DEFAULT_UPLOAD_SERVER_PORT;
TCHAR runtime_path[MAX_PATH+1];
TCHAR runtime_dirname[MAX_PATH+1];
TCHAR config_file[MAX_PATH+1];
if (0 != ::GetModuleFileName(NULL, runtime_path, MAX_PATH)) {
TCHAR tmp[MAX_PATH+1];
_tsplitpath_s(runtime_path, tmp, runtime_dirname, tmp, tmp);
}
lstrcpy(config_file, runtime_dirname);
lstrcat(config_file, _T("\\gyazo.ini"));
if (PathFileExists(config_file)) {
LPCTSTR SECTION_NAME = _T("gyazo");
GetPrivateProfileString(SECTION_NAME, _T("server"), DEFAULT_UPLOAD_SERVER, upload_server, sizeof(upload_server), config_file);
GetPrivateProfileString(SECTION_NAME, _T("path"), DEFAULT_UPLOAD_PATH, upload_path, sizeof(upload_path), config_file);
GetPrivateProfileString(SECTION_NAME, _T("token"), DEFAULT_UPLOAD_TOKEN, upload_token, sizeof(upload_token), config_file);
//GetPrivateProfileString(SECTION_NAME, _T("user_agent"), DEFAULT_USER_AGENT, ua, sizeof(ua), config_file);
upload_server_port = GetPrivateProfileInt(SECTION_NAME, _T("port"), DEFAULT_UPLOAD_SERVER_PORT, config_file);
}
const char* sBoundary = "----BOUNDARYBOUNDARY----"; // boundary
const char sCrLf[] = { 0xd, 0xa, 0x0 }; // 改行(CR+LF)
TCHAR szHeader[200];
StringCchPrintf(szHeader, 200, TEXT("Auth-Token: %s\r\nContent-type: multipart/form-data; boundary=----BOUNDARYBOUNDARY----"), upload_token);
std::ostringstream buf; // 送信メッセージ
wchar_t fname[_MAX_FNAME];
wchar_t ext[_MAX_EXT];
_wsplitpath(fileName, NULL, NULL, fname, ext );
std::string data = (isPng) ? "imagedata" : "data";
LPCTSTR file = (isPng) ? _T("gyazo") : wcsncat(fname, ext, _MAX_FNAME);
size_t size = wcstombs(NULL, file, 0);
char* CharStr = new char[size + 1];
wcstombs(CharStr, file, size + 1);
// -- "imagedata" part
buf << "--";
buf << sBoundary;
buf << sCrLf;
buf << "content-disposition: form-data; name=\"";
buf << data;
buf << "\"; filename=\"";
buf << CharStr;
buf << "\"";
buf << sCrLf;
//buf << "Content-type: image/png"; // 一応
//buf << sCrLf;
buf << sCrLf;
// 本文: PNG ファイルを読み込む
std::ifstream png;
png.open(fileName, std::ios::binary);
if (png.fail()) {
MessageBox(hwnd, _T("PNG open failed"), szTitle, MB_ICONERROR | MB_OK);
png.close();
return FALSE;
}
buf << png.rdbuf(); // read all & append to buffer
png.close();
// 最後
buf << sCrLf;
buf << "--";
buf << sBoundary;
buf << "--";
buf << sCrLf;
// メッセージ完成
std::string oMsg(buf.str());
// WinInet を準備 (proxy は 規定の設定を利用)
HINTERNET hSession = InternetOpen(_T("Gyazowin/1.0"),
INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
if(NULL == hSession) {
LastErrorMessageBox(hwnd, _T("Cannot configure wininet."));
return FALSE;
}
// 接続先
HINTERNET hConnection = InternetConnect(hSession,
//.........这里部分代码省略.........
示例11: JSRequest
/**
* The function used as ZOORequest from the JavaScript environment (ZOO-API)
*
* @param cx the JavaScript context
* @param argc the number of parameters
* @param argv1 the parameter values
* @return true
* @see setHeader
*/
JSBool
JSRequest(JSContext *cx, uintN argc, jsval *argv1)
{
jsval *argv = JS_ARGV(cx,argv1);
HINTERNET hInternet;
JSObject *header;
char *url;
char *method;
char* tmpValue;
size_t dwRead;
JS_MaybeGC(cx);
hInternet=InternetOpen("ZooWPSClient\0",
INTERNET_OPEN_TYPE_PRECONFIG,
NULL,NULL, 0);
if(!CHECK_INET_HANDLE(hInternet))
return JS_FALSE;
if(argc>=2){
method=JSValToChar(cx,&argv[0]);
url=JSValToChar(cx,&argv[1]);
}
else{
method=zStrdup("GET");
url=JSValToChar(cx,argv);
}
hInternet.waitingRequests[hInternet.nb]=strdup(url);
if(argc==4){
char *body;
body=JSValToChar(cx,&argv[2]);
header=JSVAL_TO_OBJECT(argv[3]);
#ifdef ULINET_DEBUG
fprintf(stderr,"URL (%s) \nBODY (%s)\n",url,body);
#endif
if(JS_IsArrayObject(cx,header))
setHeader(&hInternet,cx,header);
#ifdef ULINET_DEBUG
fprintf(stderr,"BODY (%s)\n",body);
#endif
InternetOpenUrl(&hInternet,hInternet.waitingRequests[hInternet.nb],body,strlen(body),
INTERNET_FLAG_NO_CACHE_WRITE,0);
processDownloads(&hInternet);
free(body);
}else{
if(argc==3){
if(strncasecmp(method,"GET",3)==0){
header=JSVAL_TO_OBJECT(argv[2]);
if(JS_IsArrayObject(cx,header)){
setHeader(&hInternet,cx,header);
}
InternetOpenUrl(&hInternet,hInternet.waitingRequests[hInternet.nb],NULL,0,
INTERNET_FLAG_NO_CACHE_WRITE,0);
processDownloads(&hInternet);
}else{
char *body=JSValToChar(cx,&argv[2]);
InternetOpenUrl(&hInternet,hInternet.waitingRequests[hInternet.nb],body,strlen(body),
INTERNET_FLAG_NO_CACHE_WRITE,0);
processDownloads(&hInternet);
free(body);
}
}else{
InternetOpenUrl(&hInternet,hInternet.waitingRequests[hInternet.nb],NULL,0,
INTERNET_FLAG_NO_CACHE_WRITE,0);
processDownloads(&hInternet);
}
}
tmpValue=(char*)malloc((hInternet.ihandle[0].nDataLen+1)*sizeof(char));
InternetReadFile(hInternet.ihandle[0],(LPVOID)tmpValue,hInternet.ihandle[0].nDataLen,&dwRead);
#ifdef ULINET_DEBUG
fprintf(stderr,"content downloaded (%d) (%s) \n",dwRead,tmpValue);
#endif
if(dwRead==0){
JS_SET_RVAL(cx, argv1,STRING_TO_JSVAL(JS_NewStringCopyN(cx,"Unable to access the file.",strlen("Unable to access the file."))));
return JS_TRUE;
}
#ifdef ULINET_DEBUG
fprintf(stderr,"content downloaded (%d) (%s) \n",dwRead,tmpValue);
#endif
JS_SET_RVAL(cx, argv1,STRING_TO_JSVAL(JS_NewStringCopyN(cx,tmpValue,strlen(tmpValue))));
free(url);
if(argc>=2)
free(method);
InternetCloseHandle(&hInternet);
JS_MaybeGC(cx);
return JS_TRUE;
}
示例12: netio_ie5_connect
netio_ie5_t *
netio_ie5_connect (char const *url)
{
int resend = 0;
DWORD type, type_s;
netio_ie5_t * netio_ie5_conn;
DWORD dw_ret;
DWORD flags =
/* INTERNET_FLAG_DONT_CACHE |*/
INTERNET_FLAG_KEEP_CONNECTION |
INTERNET_FLAG_PRAGMA_NOCACHE |
INTERNET_FLAG_RELOAD |
INTERNET_FLAG_NO_CACHE_WRITE |
INTERNET_FLAG_EXISTING_CONNECT | INTERNET_FLAG_PASSIVE;
if (internet == 0)
{
HINSTANCE h = LoadLibrary ("wininet.dll");
if (!h)
{
/* XXX - how to return an error code? */
g_warning("Failed to load wininet.dll");
return NULL;
}
/* pop-up dialup dialog box */
/* XXX - do we need the dialup box or simply don't attempt an update in this case? */
dw_ret = InternetAttemptConnect (0);
if (dw_ret != ERROR_SUCCESS) {
g_warning("InternetAttemptConnect failed: %u", dw_ret);
return NULL;
}
internet = InternetOpen ("Wireshark Update", INTERNET_OPEN_TYPE_PRECONFIG,
NULL, NULL, 0);
if(internet == NULL) {
g_warning("InternetOpen failed %u", GetLastError());
return NULL;
}
}
netio_ie5_conn = g_malloc(sizeof(netio_ie5_t));
netio_ie5_conn->connection = InternetOpenUrl (internet, url, NULL, 0, flags, 0);
try_again:
#if 0
/* XXX - implement this option */
if (net_user && net_passwd)
{
InternetSetOption (connection, INTERNET_OPTION_USERNAME,
net_user, strlen (net_user));
InternetSetOption (connection, INTERNET_OPTION_PASSWORD,
net_passwd, strlen (net_passwd));
}
#endif
#if 0
/* XXX - implement this option */
if (net_proxy_user && net_proxy_passwd)
{
InternetSetOption (connection, INTERNET_OPTION_PROXY_USERNAME,
net_proxy_user, strlen (net_proxy_user));
InternetSetOption (connection, INTERNET_OPTION_PROXY_PASSWORD,
net_proxy_passwd, strlen (net_proxy_passwd));
}
#endif
if (resend)
if (!HttpSendRequest (netio_ie5_conn->connection, 0, 0, 0, 0))
netio_ie5_conn->connection = 0;
if (!netio_ie5_conn->connection)
{
switch(GetLastError ()) {
case ERROR_INTERNET_EXTENDED_ERROR:
{
char buf[2000];
DWORD e, l = sizeof (buf);
InternetGetLastResponseInfo (&e, buf, &l);
MessageBox (0, buf, "Internet Error", 0);
}
break;
case ERROR_INTERNET_NAME_NOT_RESOLVED:
g_warning("Internet error: The servername could not be resolved");
break;
case ERROR_INTERNET_CANNOT_CONNECT:
g_warning("Internet error: Could not connect to the server");
break;
default:
g_warning("Internet error: %u", GetLastError ());
}
return NULL;
}
type_s = sizeof (type);
InternetQueryOption (netio_ie5_conn->connection, INTERNET_OPTION_HANDLE_TYPE,
&type, &type_s);
switch (type)
{
//.........这里部分代码省略.........
示例13: baidu_download
BOOL baidu_download(CString dfile, CString token, CString fname,DWORD *process)
{
if (dfile == L"")
{
MessageBox(NULL,L"Îļþ·¾¶²»ÄÜΪ¿Õ", 0, 0);
return FALSE;
}
if (token == L"")
{
MessageBox(NULL, L"token²»ÄÜΪ¿Õ", 0, 0);
return FALSE;
}
if (fname == L"")
{
MessageBox(NULL, L"ÎļþÃû²»ÄÜΪ¿Õ", 0, 0);
return FALSE;
}
CString url(L"/rest/2.0/pcs/file?method=download&path=%2Fapps%2Fhitdisk%2F" + fname + L"&access_token=" + token);
DWORD headlength;
DWORD FileLength;//Îļþ³¤¶È
TCHAR* szBuff;//»º³åÇø
DWORD bfsize = 1024 * 64;//»º³åÇø´óС
TCHAR* FileBuff;//½âÎöÎļþ³¤¶ÈÖ¸Õë
BOOL bResult = TRUE;
HINTERNET hRequest = NULL;
HINTERNET hConnect = NULL;
HINTERNET hnet = InternetOpen(TEXT("Test"), INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
hConnect = InternetConnect(hnet, TEXT("pcs.baidu.com"), 443, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
hRequest = HttpOpenRequest(hConnect, TEXT("GET"), url, NULL, NULL, NULL, INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP | INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_NO_AUTH | INTERNET_FLAG_NO_COOKIES | INTERNET_FLAG_NO_UI | INTERNET_FLAG_SECURE | INTERNET_FLAG_IGNORE_CERT_CN_INVALID | INTERNET_FLAG_RELOAD, 0);
bResult = HttpSendRequest(hRequest, NULL, 0, NULL, 0);
//½âÎöÎļþ³¤¶È
DWORD i;
szBuff = new TCHAR[bfsize];
headlength = bfsize;
bResult = HttpQueryInfo(hRequest, HTTP_QUERY_RAW_HEADERS_CRLF, szBuff, &headlength, NULL);
FileBuff = wcsstr(szBuff, L"Content-Length");
FileBuff += 16;
for (i = 0;; i++)
{
if (FileBuff[i] == '\r')
break;
}
FileLength = CharToDword(FileBuff, i);
CFile cfile(dfile, CFile::modeWrite | CFile::modeCreate);
DWORD wbfclength = 0;//»º³åÇøµ±Ç°Êý¾Ý³¤¶È
DWORD wbfsize = 1024 * 1024;//»º³åÇø´óС
char *WriteBuffer = new char[wbfsize];//ÎļþдÈ뻺³åÇø
CString show_process;
DWORD dwBytesAvailable;
DWORD FileReceived = 0;
BOOL error = TRUE;
BOOL cmp = 0;
while (InternetQueryDataAvailable(hRequest, &dwBytesAvailable, 0, 0))
{
DWORD dwBytesRead;
if (dwBytesAvailable <= bfsize)
{
bResult = InternetReadFile(hRequest, szBuff, dwBytesAvailable, &dwBytesRead);
}
else
{
bResult = InternetReadFile(hRequest, szBuff, bfsize, &dwBytesRead);
}
FileReceived += dwBytesRead;
CopyMemory(WriteBuffer + wbfclength, szBuff, dwBytesRead);
if (error)
{
szBuff[13] = '\0';
cmp = _strnicmp((char *)szBuff,"{\"error_code\"" , 13);
if (cmp == 0)
{
*process = 100;
InternetCloseHandle(hRequest);
InternetCloseHandle(hConnect);
InternetCloseHandle(hnet);
cfile.Close();
cfile.Remove(dfile);
delete[] szBuff;
delete[] WriteBuffer;
return FALSE;
}
}
wbfclength += dwBytesRead;
if (wbfclength > wbfsize - bfsize)
{
cfile.Write(WriteBuffer, wbfclength);
wbfclength = 0;
}
*process = (DWORD)(100 * (double)FileReceived / FileLength);
if (dwBytesRead == 0)
//.........这里部分代码省略.........
示例14: Close
BOOL vmsPostRequest::Send(LPCTSTR ptszServer, LPCTSTR ptszFilePath, LPCVOID pvData, DWORD dwDataSize, LPCTSTR ptszContentType, std::string *pstrResponse)
{
Close ();
DWORD dwAccessType = INTERNET_OPEN_TYPE_PRECONFIG;
if (m_pProxyInfo)
dwAccessType = m_pProxyInfo->tstrAddr.empty () ? INTERNET_OPEN_TYPE_DIRECT : INTERNET_OPEN_TYPE_PROXY;
m_hInet = InternetOpen (m_tstrUserAgent.c_str (), dwAccessType,
dwAccessType == INTERNET_OPEN_TYPE_PROXY ? m_pProxyInfo->tstrAddr.c_str () : NULL, NULL, 0);
if (m_hInet == NULL)
return FALSE;
PostInitWinInetHandle (m_hInet);
m_hConnect = InternetConnect (m_hInet, ptszServer, INTERNET_DEFAULT_HTTP_PORT,
NULL, NULL, INTERNET_SERVICE_HTTP, 0, NULL);
if (m_hConnect == NULL)
return FALSE;
#ifdef DEBUG_SHOW_SERVER_REQUESTS
TCHAR tszTmpPath [MAX_PATH];
GetTempPath (MAX_PATH, tszTmpPath);
TCHAR tszTmpFile [MAX_PATH];
_stprintf (tszTmpFile, _T ("%s\\si_serv_req_%d.txt"), tszTmpPath, _c++);
HANDLE hLog = CreateFile (tszTmpFile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
DWORD dwLogWritten;
#define LOG_REQ(s) WriteFile (hLog, s, strlen (s), &dwLogWritten, NULL)
#define LOG_REQ_OPEN CloseHandle (hLog); ShellExecute (NULL, "open", tszTmpFile, NULL, NULL, SW_SHOW);
char szTmp [10000] = ""; DWORD dwTmp = 10000;
#define LOG_REQ_HTTP_HDRS *szTmp = 0; HttpQueryInfo (m_hRequest, HTTP_QUERY_RAW_HEADERS_CRLF | HTTP_QUERY_FLAG_REQUEST_HEADERS, szTmp, &dwTmp, 0); LOG_REQ (szTmp);
#define LOG_REQ_ALL LOG_REQ_HTTP_HDRS; LOG_REQ ((LPCSTR)pvData);
#define LOG_RESP_HTTP_HDRS *szTmp = 0; HttpQueryInfo (m_hRequest, HTTP_QUERY_RAW_HEADERS_CRLF, szTmp, &dwTmp, 0); LOG_REQ (szTmp);
DWORD dwErr;
#else
#define LOG_REQ(s)
#define LOG_REQ_OPEN
#define LOG_REQ_HTTP_HDRS
#define LOG_RESP_HTTP_HDRS
#define LOG_REQ_ALL
#endif
m_hRequest = HttpOpenRequest (m_hConnect, _T ("POST"), ptszFilePath, NULL, NULL, NULL,
INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_NO_UI |
INTERNET_FLAG_PRAGMA_NOCACHE, 0);
if (m_hRequest == NULL)
{
DWORD dwErr = GetLastError ();
LOG_REQ ("SERVER FAILURE\r\n");
LOG_REQ_OPEN;
SetLastError (dwErr);
return FALSE;
}
ApplyProxyAuth (m_hRequest);
if (ptszContentType)
{
tstring tstr = _T ("Content-Type: ");
tstr += ptszContentType;
tstr += _T ("\r\n");
HttpAddRequestHeaders (m_hRequest, tstr.c_str (), tstr.length (), HTTP_ADDREQ_FLAG_ADD|HTTP_ADDREQ_FLAG_REPLACE);
}
#ifdef vmsPostRequest_USE_NO_HTTPSENDREQUESTEX
if (FALSE == HttpSendRequest (m_hRequest, NULL, 0, (LPVOID)pvData, dwDataSize))
return FALSE;
#else
INTERNET_BUFFERS buffs;
ZeroMemory (&buffs, sizeof (buffs));
buffs.dwStructSize = sizeof (buffs);
buffs.dwBufferTotal = dwDataSize;
if (FALSE == HttpSendRequestEx (m_hRequest, &buffs, NULL, 0, 0))
{
PUL (" >>> HttpSendRequestEx failed.");
LOG_REQ ("SERVER FAILURE\r\n");
LOG_REQ_OPEN;
return FALSE;
}
if (FALSE == MyInternetWriteFile (m_hRequest, pvData, dwDataSize))
{
PUL (" >>> MyInternetWriteFile failed.");
LOG_REQ ("SERVER FAILURE\r\n");
LOG_REQ_OPEN;
return FALSE;
}
if (FALSE == HttpEndRequest (m_hRequest, NULL, 0, 0))
{
PUL (" >>> HttpEndRequest failed.");
LOG_REQ_ALL;
LOG_REQ ("\r\n\r\n");
LOG_RESP_HTTP_HDRS;
LOG_REQ ("SERVER FAILURE\r\n");
LOG_REQ_OPEN;
return FALSE;
}
#endif
//.........这里部分代码省略.........
示例15: ASSERT
void CFTPTransferDlg::TransferThread()
{
//Create the Internet session handle (if needed)
if (!m_bUsingAttached)
{
ASSERT(m_hInternetSession == NULL);
// m_hInternetSession = ::InternetOpen(AfxGetAppName(), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
m_hInternetSession = InternetOpen("Ftp", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
if (m_hInternetSession == NULL)
{
TRACE(_T("Failed in call to InternetOpen, Error:%d\n"), ::GetLastError());
HandleThreadErrorWithLastError(IDS_FTPTRANSFER_GENERIC_ERROR);
return;
}
//Should we exit the thread
if (m_bAbort)
{
PostMessage(WM_FTPTRANSFER_THREAD_FINISHED);
return;
}
}
ASSERT(m_hInternetSession);
//Setup the status callback function on the Internet session handle
INTERNET_STATUS_CALLBACK pOldCallback = ::InternetSetStatusCallback(m_hInternetSession, _OnStatusCallBack);
if (pOldCallback == INTERNET_INVALID_STATUS_CALLBACK)
{
TRACE(_T("Failed in call to InternetSetStatusCallback, Error:%d\n"), ::GetLastError());
HandleThreadErrorWithLastError(IDS_FTPTRANSFER_GENERIC_ERROR);
return;
}
//Should we exit the thread
if (m_bAbort)
{
if (pOldCallback)
::InternetSetStatusCallback(m_hInternetSession, pOldCallback);
PostMessage(WM_FTPTRANSFER_THREAD_FINISHED);
return;
}
//Make the connection to the FTP server (if needed)
if (!m_bUsingAttached)
{
ASSERT(m_hFTPConnection == NULL);
ASSERT(m_sServer.GetLength());
if (m_sUserName.GetLength())
// m_hFTPConnection = ::InternetConnect(m_hInternetSession, m_sServer, m_nPort, m_sUserName,
// m_sPassword, INTERNET_SERVICE_FTP, 0, (DWORD) this);
m_hFTPConnection = ::InternetConnect(m_hInternetSession, m_sServer, m_nPort, m_sUserName,
m_sPassword, INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
else
m_hFTPConnection = ::InternetConnect(m_hInternetSession, m_sServer, m_nPort, NULL,
NULL, INTERNET_SERVICE_FTP, 0, (DWORD) this);
if (m_hFTPConnection == NULL)
{
TRACE(_T("Failed in call to InternetConnect, Error:%d\n"), ::GetLastError());
if (pOldCallback)
::InternetSetStatusCallback(m_hInternetSession, pOldCallback);
HandleThreadErrorWithLastError(IDS_FTPTRANSFER_FAIL_CONNECT_SERVER);
return;
}
//Should we exit the thread
if (m_bAbort)
{
if (pOldCallback)
::InternetSetStatusCallback(m_hInternetSession, pOldCallback);
PostMessage(WM_FTPTRANSFER_THREAD_FINISHED);
return;
}
}
ASSERT(m_hFTPConnection);
//Start the animation to signify that the download is taking place
PlayAnimation();
//Update the status control to reflect that we are getting the file information
SetStatus(IDS_FTPTRANSFER_GETTING_FILE_INFORMATION);
// Get the length of the file to transfer
DWORD dwFileSize = 0;
BOOL bGotFileSize = FALSE;
if (m_bDownload)
{
WIN32_FIND_DATA wfd;
HINTERNET hFind = ::FtpFindFirstFile(m_hFTPConnection, m_sRemoteFile, &wfd, INTERNET_FLAG_RELOAD |
INTERNET_FLAG_DONT_CACHE, (DWORD) this);
if (hFind)
{
//Set the progress control range
bGotFileSize = TRUE;
dwFileSize = (DWORD) wfd.nFileSizeLow;
// SetProgressRange(dwFileSize);
SetProgressRange(0,100);
//Destroy the enumeration handle now that we are finished with it
InternetCloseHandle(hFind);
//.........这里部分代码省略.........