PHP POST请求内部的POST请求 [英] PHP Post Request inside a POST Request

查看:295
本文介绍了PHP POST请求内部的POST请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个联系表单,当前操作为 http://www.siteA.com/ContactInfo.php ,它发送字段和值。
在ContactInfo.php,我只是捕获的值,发送和电子邮件到y @ zx

There is a contact form which current action is http://www.siteA.com/ContactInfo.php, it sends fields and values. In ContactInfo.php, i just catch the values and send and email to y@z.x

但是,在ContactInfo.php,我需要发送数据到其他域 http://www.SiteB.com/Reg.aspx

BUT, inside ContactInfo.php, I need to send the same data to another destination, in other domain http://www.SiteB.com/Reg.aspx

I尝试创建一个http POST请求到SiteB,但它不工作,即使与同一网站中的另一个文件。

I have tryed out to create an http POST request to SiteB, but It doesn't work, even with another file in the same site.

我现在没有代码,但类似于此结构。

I have not the code right now, but it's similar to this structure.

<? php
   //ContactInfo.php
   // CATCTH VALUES and SEND EMAIL

   // CREATE Http POST REquest to another www.siteB.com/Reg.aspx
?>

我试过使用... HttpRequest对象,cURL,

I have tryed out using... HttpRequest object, cURL, and the other one...i can't remember the name.

推荐答案

您可以使用cURL( http://www.php.net/manual/en/curl.examples.php ) / p>

You can try something like this using cURL (http://www.php.net/manual/en/curl.examples.php) ..

$sub_req_url = "http://www.siteB.com/Reg.aspx";

$ch = curl_init($sub_req_url);
$encoded = '';

// include GET as well as POST variables; your needs may vary.
foreach($_GET as $name => $value) {
  $encoded .= urlencode($name).'='.urlencode($value).'&';
}

foreach($_POST as $name => $value) {
  $encoded .= urlencode($name).'='.urlencode($value).'&';
}

// chop off last ampersand
$encoded = substr($encoded, 0, strlen($encoded)-1);

curl_setopt($ch, CURLOPT_POSTFIELDS,  $encoded);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_exec($ch);
curl_close($ch);

Shamly

这篇关于PHP POST请求内部的POST请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆