Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.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中如何将post发送到远程url并重定向到url_Php_Codeigniter_Post_Curl - Fatal编程技术网

在php中如何将post发送到远程url并重定向到url

在php中如何将post发送到远程url并重定向到url,php,codeigniter,post,curl,Php,Codeigniter,Post,Curl,我以前使用过curl,我想通过POST将数据从位置A发送到位置B,最后的位置是B而不是A。虽然事实上最后一个URL是一个使用curl的URL,而不是我真正想要的,如何解决这个问题 我之前用过卷曲这个方法,我希望通过邮递方法把数据从地址A.发送到地址B而且最后的地址是B而不是A.但是事实上用卷曲的话最后的地址是A.不是我事实上期望的,怎样解决这个问题? 我的代码(我使用CI框架): 您可以尝试使用stream\u context\u create和file\u get\u contents进行此操

我以前使用过curl,我想通过POST将数据从位置A发送到位置B,最后的位置是B而不是A。虽然事实上最后一个URL是一个使用curl的URL,而不是我真正想要的,如何解决这个问题

我之前用过卷曲这个方法,我希望通过邮递方法把数据从地址A.发送到地址B而且最后的地址是B而不是A.但是事实上用卷曲的话最后的地址是A.不是我事实上期望的,怎样解决这个问题?

我的代码(我使用CI框架):


您可以尝试使用
stream\u context\u create
file\u get\u contents
进行此操作,并将数据作为数组发送

    $url = "http://localhost/Test2/index.php/see/b";

    $data = array('act' => 'botton', 'botton' => 'bar');

    $options = array(
        'http' => array(
            'header'  => "Content-type: application/x-www-form-urlencoded",
            'method'  => 'POST',
            'content' => http_build_query($data),
        ),
    );
    $context  = stream_context_create($options);
    $result = file_get_contents($url, false, $context);
另一端将以以下方式接收:

    $act = $this->input->post('act');
    $botton = $this->input->post('botton');

我不确定我是否完全遵循,但如果您想将数据从A发布到B,然后将用户在其web浏览器中重定向到B,只需在发布完成后向用户发送标题,例如
标题(“位置:http://b.example.com)
。我认为您需要的是一个基本的表单功能,将表单标签的action属性设置为位置B-无需使用curl。如果不使用curl,该怎么办?似乎您想点击像
localhost/Test2/index.php/see/a
这样的url,然后用一些post数据重定向到link
localhost/Test2/index.php/see/B
。您可以不要使用curl。你需要做一些tric。当你进入page-a时,保留一个带有这些值的表单,并将表单操作url设置为page-b和method post。然后添加一些javascript自动提交表单。希望你理解。它在服务器上运行,js没有用。谢谢你的回答,但是它不起作用。我输入了url““而且没有显示任何内容,URL仍然是A它们是不同的服务器吗?”?您会收到什么错误消息?
    $url = "http://localhost/Test2/index.php/see/b";

    $data = array('act' => 'botton', 'botton' => 'bar');

    $options = array(
        'http' => array(
            'header'  => "Content-type: application/x-www-form-urlencoded",
            'method'  => 'POST',
            'content' => http_build_query($data),
        ),
    );
    $context  = stream_context_create($options);
    $result = file_get_contents($url, false, $context);
    $act = $this->input->post('act');
    $botton = $this->input->post('botton');