doudai8083 2016-07-15 09:05
浏览 19

从其他服务器登录后重定向到服务器

I have two server(say server1 and server2). There is a login panel on server1, if I login using server1 then I need to redirect to server2.

Here is the curl code I have:

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"

How can implement this using 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 . "
";
 } else {
         $error = curl_error($ch). '(' .curl_errno($ch). ')';
         echo $error . "
";
 }

 // Close connection
 curl_close($ch);
 ?>

Response I get: Failed to connect to server1(i.e the url Iam using): Connection timed out(7)

  • 写回答

1条回答 默认 最新

  • dongshou1856 2016-07-15 09:16
    关注
    1. $post_body is not defined.
    2. you are using cookie_file however in you working curl case there is no cookies being sent. so at list remove cookies related like for a trail.
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度