問題已解決:
是因為云主機的問題,需要在本地進行解析,而且不能用公網(wǎng)ip,要用127.0.0.1
非常感謝大佬的指導,解決了這個困擾大半天的困惑,大佬一語道破,解決問題,非常感謝?。?!
1、部署在linux服務器上了,并且是兩個不同站點的網(wǎng)址請求,并非同一個進程
2、用webman框架,網(wǎng)站部署后可以正常訪問 https://push.21c.xin/ ,但是用curl請求網(wǎng)站時總是返回false,
3、同樣的代碼,更換請求其它網(wǎng)址可以正常返回值,這是服務器的配置問題嗎?怎么修改呢,找了很多方案都不行,特請教大佬!
測試網(wǎng)址:https://sso.21c.xin/passport/index/curl?url=https://baidu.com 可以正常返回百度的首頁內(nèi)容
var_dump($tmpInfo); 返回html源碼
var_dump(curl_errno($curl)); 返回0
var_dump(curl_getinfo($curl, CURLINFO_HTTP_CODE)); 返回200
curl訪問 網(wǎng)址 https://sso.21c.xin/passport/index/curl?url=https://push.21c.xin/ 卻返回為false
var_dump($tmpInfo); 返回false
var_dump(curl_errno($curl)); 返回52
var_dump(curl_getinfo($curl, CURLINFO_HTTP_CODE)); 返回0
public function curl( ): Response
{
$curl = new Curl();
$url =request()->get('url','https://sso.21c.xin');
$result = $curl->get($url);
var_dump($result);
return json($result);
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'X-AjaxPro-Method:ShowList',
'Content-Type: application/json; charset=utf-8',
'Content-Length: ' . strlen($data_string))
);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
$data = curl_exec($ch);
curl_close($ch);
return json_decode($data, true);
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_REFERER, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($ch);
curl_close($ch);
return $result;
https://sso.21c.xin/passport/index/curl1?url=https://baidu.com 用你代碼寫了這個是正??梢栽L問的
但是https://sso.21c.xin/passport/index/curl1?url=https://push.21c.xin/ 還是返回false
應該是服務器設置的問題嗎
你怎么寫的代碼啊
public function curl1( )
{
$url = input('url')?:'https://sso.21c.xin';
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_REFERER, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($ch);
curl_close($ch);
var_dump($result);
return json($result);
}
剛按照你發(fā)的代碼也是不可以呢,返回依然是false
,這能訪問就怪了
public function curl1( )
{
$url = input('url')?:'https://push.21c.xin/';
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_REFERER, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($ch);
curl_close($ch);
var_dump($result);
return json($result);
}
請求 https://push.21c.xin/
url可以傳參,更改請求的網(wǎng)址
string(21) "https://push.21c.xin/"
string(11) "curl 參數(shù)"
string(21) "https://push.21c.xin/"
string(0) ""
string(3) "Get"
array(0) {
}
string(17) "curl 參數(shù)結束"
string(15) "$tmpInfo 信息"
bool(false)
int(52)
int(0)
提問把系統(tǒng)環(huán)境帶上啊。如果是windows開發(fā),windows是單進程的,就一個進程不能自己請求自己
我這瀏覽器都沒辦法訪問你的域名,顯示超時,telnet也連接超時。
telnet push.21c.xin 443
Trying 43.154.4.5...
^C
telnet sso.21c.xin 443
Trying 43.154.4.5...
^C
你的服務器估計也無法訪問你的域名,在你服務器上telnet sso.21c.xin 443
試下吧??纯词遣皇鞘褂昧舜?cdn什么的
[root@mail sso.21c.xin]# telnet sso.21c.xin
-bash: telnet: command not found
[root@mail sso.21c.xin]# ping sso.21c.xin
PING hk1.domainagent.pub (43.154.4.5) 56(84) bytes of data.
ping和telnet是不同的協(xié)議,一個icmp,一個tcp,ping通不代表tcp能連接,反過來也是。
apt-get install telnet 或者 yum install telnet 裝下telnet命令
telnet命令是 telnet sso.21c.xin 443
,端口號加上
[root@mail sso.21c.xin]# telnet sso.21c.xin 443
Trying 43.154.4.5...
Connected to sso.21c.xin.
Escape character is '^]'.
沒有問題呀我這里
GuzzleHttp\Exception\ConnectException: cURL error 52: Empty reply from server (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://push.21c.xin/
還有你webman那邊是不是 nginx代理的,你得看看你得協(xié)議 是不是http1.0 的,你用的是http1.1請求的,導致協(xié)議不一致
location / {
proxy_pass http://127.0.0.1:9901;
index index.php index.html error/index.html;
autoindex off;
proxy_set_header Host $host;
proxy_http_version 1.0;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}