1
我有兩臺服務器(比如server1和server2)。如果我使用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);
?>
響應我得到: (即使用的URL IAM)無法連接到服務器1:連接超時(7)
仍然相同的迴應@enRaiser – Aashi
你可以再次更新代碼。與上述變化。所以在名單上別人可以開始新鮮。 – enRaiser