我有两台服务器(比如server1和server2)。 server1上有一个登录面板,如果我使用server1登录,那么我需要重定向到server2。
这是我的卷曲代码:
Sample Curl request
curl -X POST -H "user_name: aaa" -H "auth_type: email" -H "app_key: someapikey" -H "platform: Android_MDA" -H "password: 123456" -H "Cache-Control: no-cache" -H "Content-Type: application/x-www-form-urlencoded" -d '' "here is server1 login url"
如何使用PHP实现这一点。
Here is what I had done so far:
<?php
$post_fields = '{"login": "aaa", "password": "123456"}';
$cookie_file = tempnam('/temp', 'cookie');
$ch = curl_init('here is server1 login url');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_body);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_exec($ch);
// Execute request and read response
$response = curl_exec($ch);
// Check errors
if ($response) {
echo $response . "\n";
} else {
$error = curl_error($ch). '(' .curl_errno($ch). ')';
echo $error . "\n";
}
// Close connection
curl_close($ch);
?>
我得到的回应: 无法连接到server1(即使用的网址):连接超时(7)
答案 0 :(得分:0)