简体   繁体   English

cURL无法在免费主机中连接,但在我的本地主机上可以正常工作

[英]cURL can't connect in a free host but works fine in my localhost

I created a small web app, with the feature of being able to Sign in with a Twitter account, by connecting with OAuth. 我创建了一个小型Web应用程序,其功能是可以通过与OAuth连接来使用Twitter帐户登录。 It worked like charm for a few months, but now it stopped working. 它像魅力一样工作了几个月,但现在停止了工作。 This is a quick and summarized overview "Sign in with twitter" algorithm. 这是一个快速汇总的概述“使用Twitter登录”算法。

The URL generated in step 2 is fine because I tried manually copying it in Google Chrome, and it shows a beautiful access token, so the problem isn't there (I think). 步骤2中生成的URL很好,因为我尝试在Google Chrome浏览器中手动将其复制,并且该URL显示了漂亮的访问令牌,因此问题不存在(我认为)。 In the step 3, I have a really small method that should do some very basic stuff: Connect to the URL generated before, retrieve the content and return it. 在第3步中,我有一个非常小的方法,应该执行一些非常基础的工作:连接到之前生成的URL,检索内容并返回它。

In my localhost Using EasyPHP 12.1, it works perfectly, as usual, but in the free host that i'm using (000webhost) it doesn't work anymore. 在使用EasyPHP 12.1的本地主机中,它像往常一样完美运行,但是在我正在使用的免费主机(000webhost)中,它不再起作用。 When trying to connect, it just timeouts. 尝试连接时,它只是超时。 The HTTPCodeError is 0 and the CurlError is "Couldn't connect to host". HTTPCodeError为0,CurlError为“无法连接到主机”。

This is the method used to connect to the URL. 这是用于连接到URL的方法。

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);    

$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$response = curl_exec($ch);

curl_close($ch);
return $response;

And this is an example of a URL used with that method: https://api.twitter.com/oauth/request_token?oauth_consumer_key=DLZZTIxpY19FnWJNtqw5A&oauth_nonce=1369452195&oauth_signature=DIetumiKqJu66XXVvDDHdepnP9M%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1369452195&oauth_version=1.0 这是与该方法一起使用的URL的示例: https : //api.twitter.com/oauth/request_token?oauth_consumer_key=DLZZTIxpY19FnWJNtqw5A&oauth_nonce=1369452195&oauth_signature=DIetumiKqJu66XXVvDDHdepnP9_amp_sign_ature_amp_1.0_ature_amp_meth__ature_version_od________________n__auth___s_n_auth_Og_O_P_M_H_T_P_M_H_T_O_P_M_H_T_P_M_H_P_P_M_T_P_M_T_P_P_M_T_P_M_H_T_P_T_P_M_H_O_P_M_T_P_M_H_P_M_H

I've been trying to fix it all day long, but now I have no idea even of what to try. 我整天都在尝试修复它,但是现在我什至不知道该尝试什么。 The files are the very same in my localhost and in the 000webhost. 这些文件在我的本地主机和000webhost中是完全相同的。 If you could enlighten me I would be very happy. 如果您能启发我,我将非常高兴。 I'll take my pants off for answers if it's needed. 如果需要的话,我会脱下裤子寻求答案。 Thank you very much. 非常感谢你。

It might be possible that Twitter has blacklisted (blocked) your free host's servers or IP address. Twitter可能将您的免费主机的服务器或IP地址列入了黑名单(已阻止)。 This can happen if other users on the server abuse the API. 如果服务器上的其他用户滥用该API,则会发生这种情况。

The only thing I can think of is that your free web hosting service blocks it. 我唯一想到的是您的免费网络托管服务会阻止它。 You know these services are perfect as long as everything is very simple. 只要一切都很简单,您就会知道这些服务是完美的。 The moment things become complicated you run into restrictions implemented by the provider. 一旦事情变得复杂,您就会遇到提供商所实施的限制。 Most of these services limit band width, disk space, server use, support, uploading and more. 这些服务中的大多数会限制带宽,磁盘空间,服务器使用,支持,上传等等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 连接到localhost可以正常工作,但是我无法连接到localhost上的大多数子目录。 怎么了? - Connecting to localhost works fine, but I can't connect to most subdirectories on localhost. What's wrong? "当使用 IP 作为主机时,Php 无法连接到 MySQL 工作台,但在使用 localhost 时工作正常" - Php not able to connect to MySQL workbench when using IP as host, but works fine when using localhost Kohana在服务器上找不到模板,但是在localhost上可以正常工作 - Kohana can't find template on the server, but it works fine on localhost cURL无法连接到主机,但连接到我的域名地址 - cURL couldn't connect to host, but it connects to my domain address cURL无法连接到主机 - cURL couldn't connect to host cURL:“无法连接到主机” - cURL : “Couldn't connect to host” 我的 WampSever 3 Localhost 没有打开我的本地主机页面之一(但可以正常打开其他页面) - My WampSever 3 Localhost isn't opening up one of my local host pages (but opens the others fine) 无法从我的网络服务器连接到MySQL服务器,在我的个人盒子上使用完全相同的文件可以正常工作 - Can't connect to MySQL server from my webserver, works fine using the exact same file on my personal box 验证码可以在localhost上正常工作,但不能在我的主机上 - captcha works fine in localhost but not in my hosting 无法连接到本地主机 - Can't connect to localhost
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM