// WinInet.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <Strsafe.h>
#include <winsock.h>
#include <string>
#include <clocale>
int _tmain(int argc, _TCHAR* argv[])
{
setlocale(LC_ALL,"1251");
SetConsoleOutputCP(1251);
SetConsoleCP(1251);
//LPCTSTR rgpszAcceptTypes[] = {_T("Content-Type: application/json"), NULL};
HINTERNET hInternet = InternetOpen(_T("MyApp"), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
HINTERNET hConnect = InternetConnect(hInternet, _T("flow.polar.com"), INTERNET_DEFAULT_HTTPS_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 1);
const DWORD dwFlagsRequest = INTERNET_FLAG_RELOAD | INTERNET_FLAG_IGNORE_CERT_CN_INVALID | INTERNET_FLAG_NO_CACHE_WRITE
/*| INTERNET_FLAG_SECURE*/ | INTERNET_FLAG_PRAGMA_NOCACHE | INTERNET_FLAG_KEEP_CONNECTION;
HINTERNET hRequest = HttpOpenRequest(hConnect, "POST", "login", HTTP_VERSION, NULL, 0, dwFlagsRequest, 1);
//HttpQueryInfo
LPVOID lpOutBuffer[1000];
DWORD dwSize = 0;
//char* JsonData = "text=mode&options=4";
char* szPost = "returnUrl=/\r\nemail=Test@yandex.ru\r\npassword=123";
char szHeaders[1024] = {};
wsprintf(szHeaders, "Origin: https://flow.polar.com\r\nAccept: */*\r\nAccept-Language: ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3\r\nAccept-Encoding: deflate\r\nConnection: keep-alive\r\nContent-Type: application/x-www-form-urlencoded; charset=UTF-8\r\nContent-Length: %d", lstrlen(szPost));
HttpSendRequest(hRequest, szHeaders, lstrlen(szHeaders), szPost, lstrlen(szPost));
//SampleCodeOne(hRequest);
DWORD StatusCode = 0;
DWORD StatusCodeLen = sizeof(StatusCode);
HttpQueryInfo(hRequest, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &StatusCode, &StatusCodeLen, NULL);
DWORD nDataMaxSize = 17 * 1024;
char* szData = (char*)malloc(nDataMaxSize);
DWORD dwDataSize = 0;
while(true)
{
DWORD dwBytesRead = 0;
if (!::InternetReadFile(hRequest, &szData[dwDataSize], nDataMaxSize - (dwDataSize + 1), &dwBytesRead))
{
::InternetCloseHandle(hRequest);
::InternetCloseHandle(hConnect);
::InternetCloseHandle(hInternet);
return 1;
}
if(!dwBytesRead)
break;
dwDataSize += dwBytesRead;
if(dwDataSize + 1 >= nDataMaxSize)
{
nDataMaxSize += 1024;
szData = (char*)realloc(szData, nDataMaxSize);
if(!szData)
{
::InternetCloseHandle(hRequest);
::InternetCloseHandle(hConnect);
::InternetCloseHandle(hInternet);
return 1;
}
}
}
szData[dwDataSize] = 0;
InternetCloseHandle(hRequest);
InternetCloseHandle(hConnect);
InternetCloseHandle(hInternet);
HANDLE hFile = CreateFile(TEXT("C:\\Test.html"), // создаваемый файл
GENERIC_WRITE, // открывается для записи
0, // совместно не используется
NULL, // защита по умолчанию
CREATE_ALWAYS, // переписывает существующий
FILE_ATTRIBUTE_NORMAL, // обычный файл
NULL); // атрибутов шаблона нет
if (hFile != INVALID_HANDLE_VALUE)
{
DWORD dwByte = 0;
WriteFile(hFile, szData, lstrlen(szData), &dwByte, NULL);
CloseHandle(hFile);
}
system("C:\\Test.html");
}
Почему в итоге приходить 400 ERROR
The request could not be satisfied.