php 向服务器发放请求,PHP客户端向服务器端发送请求并向远程服务器发送服务器端请求...
我的方案如下:
>單擊按鈕時,客戶端將向服務器端發送請求
>一旦服務器端收到請求,它將向遠程服務器發送另一個請求以獲得結果
>一旦響應到來,服務器端應該回應客戶端的響應.
客戶
$.post('login_server.php'{act:"post",phone:phone,passwords:passwords},function(e){
alert(e);
},'json');
服務器
$act = isset($_POST["act"]) ? $_POST["act"] : "default";
if($act == "default"){
var_dump(123123);
}elseif($act == "post"){
$phone = $_POST["phone"];
$password = md5($_POST["passwords"]);
$data_array = array('phone' => $phone,'password' =>$password );
$jsonStr = json_encode($data_array);
$url = "http://xx.xx.xx.xx/xxxx/userinfo/login";
$data = http_post_json($url, $jsonStr);
echo json_encode(123);
}
function http_post_json($url, $jsonStr)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonStr);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json; charset=utf-8',
'Content-Length: ' . strlen($jsonStr)
)
);
$response = curl_exec($ch);
$abc = json_encode($response);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
return array($httpCode, $response);
}
我檢查了login_server.它可以從遠程服務器獲取響應.但如果我補充一下
$response = curl_exec($ch);
回調函數不起作用.
有沒有人知道這個?
生物圈
達蒙
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的php 向服务器发放请求,PHP客户端向服务器端发送请求并向远程服务器发送服务器端请求...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php检查在线用户,php – 检查用
- 下一篇: mysql的发展进程和特点,试述数据库技