(May 30, 2021 03:21 PM)Doomslayer Wrote: First result on google.
https://stackoverflow.com/questions/2207...e-response
Hi, thank you for the link, it was very informative.
However my problems still remains, see the code below:
Code
char* HttpRequest() {
HINTERNET hInternet = InternetOpenA("YourUserAgent", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
if (hInternet == NULL)
{
return "InternetOpenA failed(hInternet)";
}
else
{
HINTERNET hConnect = InternetConnectA(hInternet, "pastebin.com", 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, NULL);
if (hConnect == NULL)
{
return "InternetConnectA failed(hConnect == NULL)";
}
else
{
const char* parrAcceptTypes[] = { "*/*", NULL };
HINTERNET hRequest = HttpOpenRequestA(hConnect, "POST", "api/api_post.php", NULL, NULL, parrAcceptTypes, 0, 0);
if (hRequest == NULL)
{
return "HttpOpenRequestA failed(hRequest == NULL)";
}
else
{
char* hdrs = "Content-Type: application/x-www-form-urlencoded";
char* frmdata = "api_dev_key=MyAPIKey&api_option=paste&api_paste_code=TESTDATA&api_paste_private=0&api_paste_name=TEST&api_paste_expire_date=N";
BOOL bRequestSent = HttpSendRequestA(hRequest, hdrs, strlen(hdrs), frmdata, strlen(frmdata));
if (!bRequestSent)
{
return "!bRequestSent HttpSendRequestA failed";
}
else
{
char strResponse[4096];
const int nBuffSize = 1024;
char buff[nBuffSize];
BOOL bKeepReading = TRUE;
DWORD dwBytesRead = -1;
DWORD BytesAvailable = 0;
do
{
InternetQueryDataAvailable(hRequest, &BytesAvailable, 0, 0);
bKeepReading = InternetReadFile(hRequest, buff, BytesAvailable, &dwBytesRead);
strncat(strResponse, buff, dwBytesRead);
} while (BytesAvailable && dwBytesRead != 0);
return strResponse;
}
InternetCloseHandle(hRequest);
}
InternetCloseHandle(hConnect);
}
InternetCloseHandle(hInternet);
}
}
(Code taken and modified from
here)
This code is meant to create a paste on pastebin.
When returned, the output is "Bad API request, use POST request, not GET". So I seem to be making a GET request rather than a POST request... any suggestions on how to fix this?