简体   繁体   English

将多部分 POST 转发到另一个页面

[英]Forward multi-part POST to another page

Okay, I have two sites, we'll call them A and B. Site A has a mutli-part form with a file attachment;好的,我有两个站点,我们称它们为 A 和 B。站点 A 有一个带有文件附件的多部分表单; Site B has a similar form (which I'm not going to use) and a processing page that it submits to.站点 B 有一个类似的表单(我不会使用它)和一个它提交到的处理页面。 Due to browser origin policies, I'm adding a "proxy page" to Site B that I can post to from Site A. The proxy page will then need to "forward" the data to the processing page and get a response which I will use to generate JSONP for sending back to Site A.由于浏览器原始策略,我正在向站点 B 添加一个“代理页面”,我可以从站点 A 发布到该站点。然后,代理页面将需要将数据“转发”到处理页面并获得响应,我将用于生成 JSONP 以发送回站点 A。

I'd normally use the session or just generate and autosubmit a form on the proxy page but I'm not sure how to do this since it involves a file input tag.我通常会使用 session 或只是在代理页面上生成并自动提交表单,但我不确定如何执行此操作,因为它涉及文件输入标签。 I'm thinking I may be able to use something like this: http://www.php.net/manual/en/function.httprequest-send.php我想我可以使用这样的东西: http://www.php.net/manual/en/function.httprequest-send.php

Any ideas?有任何想法吗?

It'd be relatively trivial with curl.使用 curl 会相对微不足道。

$post_data = $_POST; // copy over the non-file post data
foreach($_FILES as $key => $filedat) {
   $post_data[$key] = '@' . $filedat['tmp_name'];  // add the uploaded files to the new field list
}

$ch = curl_init('http://siteb.com/proxy_page')
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$res = curl_exec($ch);

This will undoubtedly need some tweaking/fixing, but should be enough to get you started.这无疑需要一些调整/修复,但应该足以让你开始。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM