Skip to content

Instantly share code, notes, and snippets.

@CsgoBotTG
Created February 13, 2025 08:25
Show Gist options
  • Save CsgoBotTG/c1900562ecee397ab1113465c6820f0e to your computer and use it in GitHub Desktop.
Save CsgoBotTG/c1900562ecee397ab1113465c6820f0e to your computer and use it in GitHub Desktop.
get pastebin raw via wininet
#ifdef _WIN32
#include "getpastebin.h"
std::wstring CharPToWstring(const char* _charP)
{
return std::wstring(_charP, _charP + strlen(_charP));
}
std::wstring GetPastebin(HINTERNET& hInternet, HINTERNET& hConnect, const LPCWSTR& raw_url)
{
char szData[1024];
// open request
HINTERNET hRequest = ::HttpOpenRequestW(hConnect, L"GET", raw_url/*TEXT("raw/0PW9gmS7")*/, NULL, NULL, 0, INTERNET_FLAG_SECURE, 1);
if (hRequest != NULL)
{
// send request
BOOL isSend = ::HttpSendRequest(hRequest, NULL, 0, NULL, 0);
if (isSend)
{
for(;;)
{
// reading data
DWORD dwByteRead;
BOOL isRead = ::InternetReadFile(hRequest, szData, sizeof(szData) - 1, &dwByteRead);
// break cycle if error or end
if (isRead == FALSE || dwByteRead == 0)
break;
// saving result
szData[dwByteRead] = 0;
}
}
// close request
::InternetCloseHandle(hRequest);
}
return CharPToWstring(szData);
}
#endif
#pragma once
#ifdef _WIN32
#include <vector>
#include <string>
#include <Windows.h>
#include <wininet.h>
#pragma comment(lib, "wininet")
#define EXIT_SUCCESS 0;
#define EXIT_NONWIN 1;
std::wstring CharPToWstring(const char* _charP);
std::wstring GetPastebin(HINTERNET& hInternet, HINTERNET& hConnect, const LPCWSTR& raw_url);
#endif
#ifdef _WIN32
#include "getpastebin.h"
const wchar_t raw_url[] = L"raw/DF8VfyC4";
int main()
{
#ifdef _WIN32
while (!InternetCheckConnection(TEXT("https://pastebin.com"), FLAG_ICC_FORCE_CONNECTION, 0))
{
printf("no connection\n");
Sleep(10000);
}
printf("connected to pastebin\n");
// open http wininet
HINTERNET hInternet = ::InternetOpen(TEXT("PastebinCodePython"), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
if (hInternet == NULL) {
printf("InternetOpen failed: %d\n", GetLastError());
return GetLastError();
}
// open HTTP session
HINTERNET hConnect = ::InternetConnect(hInternet, TEXT("pastebin.com"), INTERNET_DEFAULT_HTTPS_PORT, NULL,NULL, INTERNET_SERVICE_HTTP, NULL, 1);
if (hConnect == NULL) {
printf("InternetConnect failed: %d\n", GetLastError());
InternetCloseHandle(hInternet);
return GetLastError();
}
std::wstring response = GetPastebin(hInternet, hConnect, raw_url);
printf("%ls\n", response.c_str());
return EXIT_SUCCESS;
#else
return EXIT_NONWIN;
#endif
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment