【问题标题】:How to Post Action automatically in php?如何在 php 中自动发布操作?
【发布时间】:2016-08-24 03:08:37
【问题描述】:

详情在这里: 首先我会点击这个链接,例如。 http://your.app/callback?代码=abc123 然后我将从 url 的 code 变量接收值然后我想将此 url 重定向为 https://api.another.com/token 中的 POST 操作 grant_type=authorization_code& code=[CODE] url,承载code

的值

【问题讨论】:

  • 你可以使用 curl 或 file_get_contents

标签: php post-redirect-get curl-commandline


【解决方案1】:

使用卷曲:

一个例子:

<?php

// if you get the code here from the url,
$code = $_GET['code'];

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,"http://api.another.com/");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
            "token_grant_type=authorization_code&code=" + $code);

// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$server_output = curl_exec ($ch);

curl_close ($ch);

?>

【讨论】:

    猜你喜欢
    • 2020-10-07
    • 1970-01-01
    • 2014-12-16
    • 1970-01-01
    • 2011-10-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-20
    • 1970-01-01
    相关资源
    最近更新 更多