問(wèn)題已解決:
是因?yàn)樵浦鳈C(jī)的問(wèn)題,需要在本地進(jìn)行解析,而且不能用公網(wǎng)ip,要用127.0.0.1
非常感謝大佬的指導(dǎo),解決了這個(gè)困擾大半天的困惑,大佬一語(yǔ)道破,解決問(wèn)題,非常感謝?。?!
1、部署在linux服務(wù)器上了,并且是兩個(gè)不同站點(diǎn)的網(wǎng)址請(qǐng)求,并非同一個(gè)進(jìn)程
2、用webman框架,網(wǎng)站部署后可以正常訪問(wèn) https://push.21c.xin/ ,但是用curl請(qǐng)求網(wǎng)站時(shí)總是返回false,
3、同樣的代碼,更換請(qǐng)求其它網(wǎng)址可以正常返回值,這是服務(wù)器的配置問(wèn)題嗎?怎么修改呢,找了很多方案都不行,特請(qǐng)教大佬!
測(cè)試網(wǎng)址:https://sso.21c.xin/passport/index/curl?url=https://baidu.com 可以正常返回百度的首頁(yè)內(nèi)容
var_dump($tmpInfo); 返回html源碼
var_dump(curl_errno($curl)); 返回0
var_dump(curl_getinfo($curl, CURLINFO_HTTP_CODE)); 返回200
curl訪問(wèn) 網(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);
我寫的get請(qǐng)求,請(qǐng)求其它網(wǎng)站都可以正常返回,但是請(qǐng)求webman部署的網(wǎng)站不行,都是返回false
$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 用你代碼寫了這個(gè)是正??梢栽L問(wèn)的
但是https://sso.21c.xin/passport/index/curl1?url=https://push.21c.xin/ 還是返回false
應(yīng)該是服務(wù)器設(shè)置的問(wèn)題嗎
請(qǐng)求的是我自己的服務(wù)器,現(xiàn)在做微服務(wù)架構(gòu),把模塊分離了,不知道服務(wù)器要怎么設(shè)置才能解決這個(gè)問(wèn)題呢
你怎么寫的代碼啊
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
,這能訪問(wèn)就怪了
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);
}
請(qǐng)求 https://push.21c.xin/
url可以傳參,更改請(qǐng)求的網(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ù)結(jié)束"
string(15) "$tmpInfo 信息"
bool(false)
int(52)
int(0)
提問(wèn)把系統(tǒng)環(huán)境帶上啊。如果是windows開發(fā),windows是單進(jìn)程的,就一個(gè)進(jìn)程不能自己請(qǐng)求自己
我這瀏覽器都沒(méi)辦法訪問(wèn)你的域名,顯示超時(shí),telnet也連接超時(shí)。
telnet push.21c.xin 443
Trying 43.154.4.5...
^C
telnet sso.21c.xin 443
Trying 43.154.4.5...
^C
你的服務(wù)器估計(jì)也無(wú)法訪問(wèn)你的域名,在你服務(wù)器上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é)議,一個(gè)icmp,一個(gè)tcp,ping通不代表tcp能連接,反過(guò)來(lái)也是。
apt-get install telnet 或者 yum install telnet 裝下telnet命令
telnet命令是 telnet sso.21c.xin 443
,端口號(hào)加上
[root@mail sso.21c.xin]# telnet sso.21c.xin 443
Trying 43.154.4.5...
Connected to sso.21c.xin.
Escape character is '^]'.
沒(méi)有問(wèn)題呀我這里
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請(qǐng)求的,導(dǎo)致協(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;
}