Skip to content Skip to sidebar Skip to footer

How To Format HTTP Request To Discord API?

While this code works, it sends 'Bad Request'. import socket, ssl token = 'NzMyMzQ1MTcwNjK2MTR5OEU3.XrzQug.BQzbrckR-THB9eRwZi3Dn08BWrM' HOST = 'discord.com' PORT = 443 t = 'POST /

Solution 1:

t = 'POST / HTTP/1.0\r\nAuthentication: Bot {token}\r\nHost: discord.com/api/guilds/{702627382091186318}/channels\r\n\r\n'

This is not a valid HTTP request. You essentially send (line breaks added for clarity):

 POST / HTTP/1.0\r\n
 Authentication: Bot {token}\r\n
 Host: discord.com/api/guilds/{702627382091186318}/channels\r\n
 \r\n

But a correct POST request would look like this instead:

 POST /api/guilds/{702627382091186318}/channels HTTP/1.0\r\n
 Authentication: Bot {token}\r\n
 Host: discord.com\r\n
 Content-length: ...
 \r\n
 <body, where size matches Content-length header>

I.e. you have the wrong path, wrong Host header, missing body and missing Content-length header. If you really want to write your own HTTP stack instead of using existing libraries please study the standards instead of just guessing how it might look - that what standards are for.


Post a Comment for "How To Format HTTP Request To Discord API?"