• HTTP request failed, Cloudflare error, cookies disabled?
    7 replies, posted
Hi, I'm trying to pull info from discordapp.com but when I make the following http request:     HTTP({         failed = function(err)             MsgC(Color(255, 0, 0), "HTTP error: " .. err .. "\n")         end,         success = function(code, body, headers)             Discord.SelfData = util.JSONToTable(body) print(body)         end,         url = "http://discordapp.com/api/users/@me"     }) I receive no HTTP error, but the body that is printed is as follows: <!DOCTYPE html> <!--[if lt IE 7]> <html class="no-js ie6 oldie" lang="en-US"> <![endif]--> <!--[if IE 7]>    <html class="no-js ie7 oldie" lang="en-US"> <![endif]--> <!--[if IE 8]>    <html class="no-js ie8 oldie" lang="en-US"> <![endif]--> <!--[if gt IE 8]><!--> <html class="no-js" lang="en-US"> <!--<![endif]--> <head> <title>Attention Required! | Cloudflare</title> <meta charset="UTF-8" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" /> <meta name="robots" content="noindex, nofollow" /> <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1" /> <link rel="stylesheet" id="cf_styles-css" href="/cdn-cgi/styles/cf.errors.css" type="text/css" media="screen,projection" /> <!--[if lt IE 9]><link rel="stylesheet" id='cf_styles-ie-css' href="/cdn-cgi/styles/cf.errors.ie.css" type="text/css" media="screen,projection" /><![endif]--> <style type="text/css">body{margin:0;padding:0}</style>     <!--[if gte IE 10]><!--><script type="text/javascript" src="/cdn-cgi/scripts/zepto.min.js"></script><!--<![endif]--> <!--[if gte IE 10]><!--><script type="text/javascript" src="/cdn-cgi/scripts/cf.common.js"></script><!--<![endif]-->       </head> <body>   <div id="cf-wrapper">     <div class="cf-alert cf-alert-error cf-cookie-error" id="cookie-alert" data-translate="enable_cookies">Please enable cookies.</div>     <div id="cf-error-details" class="cf-error-details-wrapper">       <div class="cf-wrapper cf-header cf-error-overview">         <h1 data-translate="block_headline">Sorry, you have been blocked</h1>         <h2 class="cf-subheadline"><span data-translate="unable_to_access">You are unable to access</span> discordapp.com</h2>       </div><!-- /.header -->         <div class="cf-section cf-highlight">         <div class="cf-wrapper">           <div class="cf-screenshot-container cf-screenshot-full">                            <span class="cf-no-screenshot error"></span>                        </div>         </div>       </div><!-- /.captcha-container -->         <div class="cf-section cf-wrapper">         <div class="cf-columns two">           <div class="cf-column">             <h2 data-translate="blocked_why_headline">Why have I been blocked?</h2>               <p data-translate="blocked_why_detail">This website is using a security service to protect itself from online attacks. The action you just performed triggered the security solution. There are several actions that could trigger this block including submitting a certain word or phrase, a SQL command or malformed data.</p>           </div>             <div class="cf-column">             <h2 data-translate="blocked_resolve_headline">What can I do to resolve this?</h2>               <p data-translate="blocked_resolve_detail">You can email the site owner to let them know you were blocked. Please include what you were doing when this page came up and the Cloudflare Ray ID found at the bottom of this page.</p>           </div>         </div>       </div><!-- /.section -->         <div class="cf-error-footer cf-wrapper">   <p>     <span class="cf-footer-item">Cloudflare Ray ID: <strong>[CENSORED]</strong></span>     <span class="cf-footer-separator">&bull;</span>     <span class="cf-footer-item"><span>Your IP</span>: [CENSORED]</span>     <span class="cf-footer-separator">&bull;</span>     <span class="cf-footer-item"><span>Performance &amp; security by</span> <a href="https://www.cloudflare.com/5xx-error-landing?utm_source=error_footer" id="brand_link" target="_blank">Cloudflare</a></span>          <span class="cf-footer-separator">&bull;</span>     <span class="cf-footer-item">       <select id="lang-selector">         <option value="">Select a Language</option>         <option value="en">English</option>         <option value="es">Español</option>       </select>     </span>        </p> </div><!-- /.error-footer -->         </div><!-- /#cf-error-details -->   </div><!-- /#cf-wrapper -->     <script type="text/javascript">   window._cf_translation = {};   window._cf_transla As far as I can tell, Cloudflare is blocking my server from accessing discordapp.com because cookies are disabled in the http request. Is there any way to enable cookies to fix this? Thanks, BigTom
Discord blocked gmod's useragent Read mode here: Next Update v9
That sucks. Is there any known workaround?
I fixed it by proxying the request through my own webserver
Here is a basic proxy PHP script that will get you going, might want to add some key protection and variable checking etc <?php $options = array(     'http' => array(         'header'  => "Content-type: application/json\r\n",         'method'  => 'POST',         'content' => $_POST["content"]     ) ); $context  = stream_context_create($options); $result = file_get_contents($_POST["webhook"], false, $context); Use it in gmod lua like this: http.Post("http://mywebsite.com/discordproxy.php", { webhook = "https://discordapp.com/api/webhooks/1234/ASDFASDFASDF", content = util.TableToJSON(data), })
If you're using nginx and would prefer not to use any intermediary languages, you can use the following sample config - #This config assumes you're using https. Modify accordingly if you want port 80 (http, untested) #Modify fields accordingly server {         listen 443;         server_name discord.yourdomain.com;              root /path/to/root/dir;         access_log /path/to/discordaccess.log;         error_log /path/to/discorderror.log;         #If you use http, remove or comment out the ssl below.         ssl_certificate /path/to/your/fullchain.pem;         ssl_certificate_key /path/to/your/privkey.pem;         ssl_prefer_server_ciphers on;         ssl_dhparam /path/to/dhparam.pem;         location / {                 proxy_pass https://discordapp.com/;                 proxy_intercept_errors on;                 proxy_set_header Accept-Encoding "";                 proxy_ssl_server_name on;                 proxy_set_header CF-Connecting-IP "";                 proxy_set_header User-Agent "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36";                 proxy_ssl_verify off;         } } In this case you then treat it like it's the discord api, but supplement your own proxy url instead. So the following is how it would work to fetch a member: https://discord.yourdomain.com/api/guilds/123451234512345/members/678906890
some host like mtxsev block your request if you don't both web and game server hosted on their servers
I got around this by using a socket module to preform HTTP requests, no proxies needed.
Sorry, you need to Log In to post a reply to this thread.