Помогите загружать файл через http запрос к php файлу (c++)

 __forceinline std::string request_to_server(std::string site, std::string param)
{
    HINTERNET hInternet = InternetOpen(OBFUSCATE(""), INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);

    if (hInternet == NULL)
    {
        li(MessageBoxA)(NULL, OBFUSCATE("Cannot connect to server."), utilities::get_random_string(16).c_str(), MB_SYSTEMMODAL | MB_ICONERROR);
        return NULL;
    }
    else
    {
        std::wstring widestr;
        for (int i = 0; i < site.length(); ++i)
        {
            widestr += wchar_t(site[i]);
        }
        const wchar_t* site_name = widestr.c_str();

        std::string widestr2;
        for (int i = 0; i < param.length(); ++i)
        {
            widestr2 += wchar_t(param[i]);
        }
        const char* site_param = widestr2.c_str();

        HINTERNET hConnect = li(InternetConnectW)(hInternet, site_name, 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, NULL);

        if (hConnect == NULL)
        {
            li(MessageBoxA)(NULL, OBFUSCATE("Error sending message to server"), utilities::get_random_string(16).c_str(), MB_SYSTEMMODAL | MB_ICONERROR);
            return NULL;
        }
        else
        {
            const char* parrAcceptTypes[] = { OBFUSCATE("text/*"), NULL };

            HINTERNET hRequest = li(HttpOpenRequest)(hConnect, OBFUSCATE("POST"), site_param, NULL, NULL, parrAcceptTypes, 0, 0);

            if (hRequest == NULL)
            {
                li(MessageBoxA)(NULL, OBFUSCATE("Error sending message to server"), utilities::get_random_string(16).c_str(), MB_SYSTEMMODAL | MB_ICONERROR);
                return NULL;
            }
            else
            {
                BOOL bRequestSent = li(HttpSendRequestW)(hRequest, NULL, 0, NULL, 0);

                if (!bRequestSent)
                {
                    li(MessageBoxA)(NULL, OBFUSCATE("Error sending message to server"), utilities::get_random_string(16).c_str(), MB_SYSTEMMODAL | MB_ICONERROR);
                    return NULL;
                }
                else
                {
                    std::string strResponse;
                    const int nBuffSize = 1024;
                    char buff[nBuffSize];

                    BOOL bKeepReading = true;
                    DWORD dwBytesRead = -1;

                    while (bKeepReading && dwBytesRead != 0)
                    {
                        bKeepReading = li(InternetReadFile)(hRequest, buff, nBuffSize, &dwBytesRead);
                        strResponse.append(buff, dwBytesRead);
                    }
                    return strResponse;
                }
                li(InternetCloseHandle)(hRequest);
            }
            li(InternetCloseHandle)(hConnect);
        }
        li(InternetCloseHandle)(hInternet);
    }
}

Вот моя функция отправления запросов

Мне нужно, с помощью этого запроса получать файл

li(sprintf)(request, OBFUSCATE("/api/test.php"));
std::string response = utilities::request_to_server(g_globals.server_side.ip, request);

TCHAR szExeFileName[MAX_PATH];
GetModuleFileName(NULL, szExeFileName, MAX_PATH);
std::string newname = utilities::get_random_string(8).c_str();
std::string extension = (OBFUSCATE("_new.dll"));
std::string newextension = newname + extension;
std::string Path = (OBFUSCATE("./")) + newextension;

URLDownloadToFileA(NULL, response.c_str(), Path.c_str(), 0, NULL);

Я хотел делать это так, но файл не загружается, если я просто напишу вместо response.c_str() вторым аргументом в UrlDownloadToFileA путь к файлу, а именно https://myurl/api/download.php, то файл скачается, но мне нужно это делать именно с моим запросом, помогите пожалуйста, извиняюсь за свою столь запутанную речь


Ответы (0 шт):