2016-07-15 66 views
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)

回答

0
  1. $ post_body没有定义。
  2. 您正在使用cookie_file,但在您工作的卷曲情况下没有发送cookie。所以在列表中删除有关跟踪相关的Cookie。
+0

仍然相同的回应@enRaiser – Aashi

+0

你可以再次更新代码。与上述变化。所以在名单上别人可以开始新鲜。 – enRaiser

相关问题