Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/EmptyTag/130.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP将json结果发布到自定义url_Php_Json - Fatal编程技术网

PHP将json结果发布到自定义url

PHP将json结果发布到自定义url,php,json,Php,Json,默认情况下,在我的web服务上,我必须向自定义用户的url发出post请求。我可以发布数组,但我想将请求作为json负载发布,下面的代码可以是post数据,但我无法从PHP获取数据 function redirect_to_customer($result = [], $redirect_url = "") { $html = '<html xmlns="http://www.w3.org/1999/xhtml"> <head>&l

默认情况下,在我的web服务上,我必须向自定义用户的url发出post请求。我可以发布数组,但我想将请求作为json负载发布,下面的代码可以是post数据,但我无法从PHP获取数据

function redirect_to_customer($result = [], $redirect_url = "")
{
    $html = '<html xmlns="http://www.w3.org/1999/xhtml">
                <head></head>
                <body onload="closethisasap();">
                <form name="redirectpost" method="POST" action="' . $redirect_url . '">
        ';
    if (!is_null($result)) {
        $result = json_encode($result);
        $html .= '<input type="hidden" value="' . str_replace('"', "'", $result) . '"> ';
    }
    $html .= "
    </form>
    </body>
    <script type=\"text/javascript\">
                        function closethisasap() {
                            document.forms[\"redirectpost\"].submit();
                        }
                    </script>
    </html>";

    echo $html;
}

发布数据后,我得到空数组

所有输入,包括
@abracadver噢,对不起,谢谢。问题解决了。请张贴回复,让我接受
<html xmlns = "http://www.w3.org/1999/xhtml">
    <head>
    </head>
    <body onload = "closethisasap();">
        <form name = "redirectpost" method = "POST" action = "http://www.sample.com/response.php">
            <input type = "hidden" value = "{'code':'-103','message':'order_id must be unique'}">
        </form>
    </body>
    <script type = "text/javascript">
        function closethisasap()
        {
            document . forms["redirectpost"] . submit();
                }
    </script>
</html>
<?php
print_r($_POST);
?>