POST 请求中的 PHP Post 请求

发布于 2024-08-21 21:32:20 字数 648 浏览 4 评论 0原文

有一个联系表单,当前操作是http://www.siteA.com/ContactInfo.php,它发送字段和值。 在 ContactInfo.php 中,我只是捕获值并发送并通过电子邮件发送到 [email protected]< /a>

但是,在 ContactInfo.php 中,我需要将相同的数据发送到其他域中的另一个目的地 http://www.SiteB.com/Reg.aspx

我尝试创建向 SiteB 发出 http POST 请求,但即使在同一站点中使用另一个文件,它也不起作用。

我现在没有代码,但它与这个结构类似。

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

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

我尝试过使用... HttpRequest 对象、cURL 和另一个...我不记得名字了。

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 [email protected]

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

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
?>

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

云醉月微眠 2024-08-28 21:32:20

您可以使用 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

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

思念满溢 2024-08-28 21:32:20

我鼓励您尝试Snoopy 类。这真的很简单:

<?php

  $vars = array("fname"=>"Jonathan","lname"=>"Sampson");
  $snoopy = new Snoopy();

  $snoopy->httpmethod = "POST";
  $snoopy->submit("http://www.siteB.com/Reg.aspx", $vars);

  # Use the following if you need to view the results
  # print $snoopy->results;

?>

I'd encourage you to try the Snoopy Class. It's really rather simple:

<?php

  $vars = array("fname"=>"Jonathan","lname"=>"Sampson");
  $snoopy = new Snoopy();

  $snoopy->httpmethod = "POST";
  $snoopy->submit("http://www.siteB.com/Reg.aspx", $vars);

  # Use the following if you need to view the results
  # print $snoopy->results;

?>
想你只要分分秒秒 2024-08-28 21:32:20

如果没有看到您的代码,很难说出问题是什么。

问题:

站点 B 是您也拥有的域还是第三方的域?如果是第三方,他们可能会运行机器人检查等,这会使您的 POST 失败。

您是否已采取任何措施来确认数据确实发送到域 B?

如果域 B 也在您的控制之下,我的猜测是它们在同一个 Web 服务器上运行 - 为什么不直接将逻辑写入域 A 页面,该页面可以执行任何需要完成的操作,而不必提交到域 B?

Without seeing your code it's hard to say what the problem is.

Questions:

Is site B a domain you also own, or is it third party? If it's third party they may be running bot checks and the like that would make your POST fail.

Have you done anything to confirm that the data is in fact being send to domain B?

If domain B is also under your control, my guess is they are running on the same web server - why not just write logic into the domain A page that does whatever it is that needs to be done without having to submit to domain B?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文