我想上傳「C:\ test.txt」到網絡服務器,當我運行程序時,文件沒有上傳,我沒有收到任何錯誤。在Web服務器Dev C++ Wininet上傳文件使用HTTP
the complete C++ code can be find here
和PHP代碼可以在這裏找到: 「http://student114.110mb.com/upload.txt」 或 「http://student114.110mb.com/upload.php」
好心幫我哪裏做錯了
#include <windows.h>
#include <wininet.h>
#include <tchar.h>
#include <iostream>
#pragma comment(lib,"wininet.lib")
using namespace std;
int main()
{
static TCHAR frmdata[] = "-----------------------------7d82751e2bc0858\nContent-Disposition: form-data; name=\"uploadedfile\"; filename=\"C:\test.txt\"\nContent-Type: text/plain\n\nfile contents here\n-----------------------------7d82751e2bc0858--";
static TCHAR hdrs[] = "Content-Type: multipart/form-data; boundary=---------------------------7d82751e2bc0858";
HINTERNET hSession = InternetOpen("MyAgent",INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
if(hSession==NULL)
{
cout<<"Error: InternetOpen";
}
HINTERNET hConnect = InternetConnect(hSession, _T("localhost"),INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 1);
if(hConnect==NULL)
{
cout<<"Error: InternetConnect";
}
HINTERNET hRequest = HttpOpenRequest(hConnect, (const char*)"POST",_T("upload.php"), NULL, NULL, (const char**)"*/*\0", 0, 1);
if(hRequest==NULL)
{
cout<<"Error: HttpOpenRequest";
}
BOOL sent= HttpSendRequest(hRequest, hdrs, strlen(hdrs), frmdata, strlen(frmdata));
if(!sent)
{
cout<<"Error: HttpSendRequest";
}
//close any valid internet-handles
InternetCloseHandle(hSession);
InternetCloseHandle(hConnect);
InternetCloseHandle(hRequest);
return 0;
}
您是否安裝小提琴手,看到正在發送的HTTP流量?我會先從那裏開始。 – Alan 2009-12-31 13:29:42
不,我沒有安裝它 – student 2009-12-31 13:37:58
當我編輯源代碼,然後我得到錯誤「錯誤:HttpSendRequest 12005」,見上面的超鏈接 – student 2009-12-31 13:46:27