doulai2573 2011-04-16 14:34
浏览 623
已采纳

有没有办法用POST请求重定向用户?

I need to redirect an user, but I need to simulate some form processing, the end point way for a POST request, so I basicly want to redirect my user as he was sending a post request.

I know I can do a page between the both and use javascript to submit an hidden form, but I'd like to avoid that.

  • 写回答

2条回答 默认 最新

  • douji9734 2011-04-16 17:24
    关注

    Im assuming that you're doing some sort of stats logging, or something, in the intermediate server?

    Another way of doing it.. have the form POST to the target URL, but use ajax to grab the form data first.

    <form id="formid" onsubmit="saveFormValues(this);return true" target="http://target/url">
    
    </form>
    

    the browser will call saveFormValues() first, and then return true indicating that the form can be processed in the normal way.

    Of course, this wont work for people without javascript. The only way of POSTing to your indermediate server, is for your intermediate server to POST the data to the target server itself using cURL. And then returning the reponse back.

    <?php
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://target/url");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $_POST);
    $output = curl_exec($ch);
    $info = curl_getinfo($ch);
    curl_close($ch);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发