小编stu*_*ent的帖子

Dev C++ Wininet使用HTTP上传文件

我想将"C:\ test.txt"上传到网络服务器,当我运行程序时,文件没有上传,我没有收到任何错误.

完整的C++代码可以在这里找到

和webserver上的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", …
Run Code Online (Sandbox Code Playgroud)

c++ upload http file wininet

2
推荐指数
1
解决办法
2万
查看次数

标签 统计

c++ ×1

file ×1

http ×1

upload ×1

wininet ×1