I have been digging for a while to see if I can find any fixes for this but I have seemed to hit a wall. At this point, I am not sure what the issue is. Every other host I have tried has worked except for discord.
WSADATA wsaData;
if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) {
cout << "WSAStartup failed.\n";
system("pause");
return 1;
}
SOCKET Socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
struct hostent* host;
host = gethostbyname("discordapp.com");
SOCKADDR_IN SockAddr;
SockAddr.sin_port = htons(80);
SockAddr.sin_family = AF_INET;
SockAddr.sin_addr.s_addr = *((unsigned long*)host->h_addr);
cout << "Connecting...\n";
if (connect(Socket, (SOCKADDR*)(&SockAddr), sizeof(SockAddr)) != 0) {
cout << "Could not connect";
system("pause");
return 1;
}
cout << "Connected.\n";
send(Socket, "GET /api/ HTTP/1.1\r\nHost: discordapp.com\r\nConnection: close\r\n\r\n", strlen("GET /api/ HTTP/1.1\r\nHost: discordapp.com\r\nConnection: close\r\n\r\n"), 0);
char buffer[10000];
int nDataLength;
while ((nDataLength = recv(Socket, buffer, 10000, 0)) > 0) {
int i = 0;
while (buffer[i] >= 32 || buffer[i] == '\n' || buffer[i] == '\r') {
cout << buffer[i];
i += 1;
}
}
closesocket(Socket);
WSACleanup();
system("pause");
return 0;
I keep getting this response no matter what I try:
HTTP/1.1 301 Moved Permanently
Date: Mon, 10 Feb 2020 21:16:57 GMT
Transfer-Encoding: chunked
Connection: close
Cache-Control: max-age=3600
Expires: Mon, 10 Feb 2020 22:16:57 GMT
Location: https://discordapp.com/api/
Set-Cookie: __cfruid=17e1ccd526aa851f5d5563850c5793a999f859c0-1581369417; path=/; domain=.discordapp.com; HttpOnly
Server: cloudflare
CF-RAY: 56311b6b0baba67b-DUB`
Is there something I am missing? The ultimate goal is to be able to post to a webhook using the api.