【问题标题】:PHP Post Request inside a POST RequestPOST 请求中的 PHP 发布请求
【发布时间】:2011-01-19 01:21:24
【问题描述】:

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

但是,在 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 和另一个...我不记得名字了。

【问题讨论】:

    标签: php post curl httprequest


    【解决方案1】:

    没有看到您的代码,很难说出问题所在。

    问题:

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

    您有没有做任何事情来确认数据实际上正在发送到域 B?

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        【解决方案3】:

        我鼓励您尝试Snoopy Class。其实很简单:

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

        【讨论】:

          猜你喜欢
          • 2017-07-13
          • 1970-01-01
          • 2021-03-11
          • 1970-01-01
          • 2015-12-06
          • 2022-11-29
          • 1970-01-01
          • 1970-01-01
          • 2021-11-30
          相关资源
          最近更新 更多