收到的 HTTP 方法无效.只接受 POST [英] The HTTP method received is not valid. Only POST is accepted

查看:28
本文介绍了收到的 HTTP 方法无效.只接受 POST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我有这个 php 文件用于我的汇丰银行使用 API 进行处理,我在其他 2 个网站上运行良好,但是在其他两个网站上相同的文件失败,我不知道为什么.我的 Web 开发人员被难住了,决定创建一个测试文件,这是测试文件中的代码:

OK, I have this php file for my HSBC bank processing using the API, I have this working fine on 2 of my other websites, however the SAME file is failing on the other two sites, I have no idea why. My web developer is stumped and decided to create a test file, Here is the code from the test file:

<?php
echo "payment processing...";
$amount = 100;// round($_POST["realamount"], 2) * 100;
$fullName = "test";//$_POST['name'];
$Address1 = "test";//$_POST['address1'];
$Address2 = "test";//$_POST['address2'];
$city ="test";// $_POST['city'];
$county = $city;
$postcode = "test";//$_POST['zipcode'];
$country = "GRB";//$_POST['country'];

$phone = "test";//$_POST['telephone'];
$email = "a@a.com";//$_POST['emailaddress'];    

$cardNumber = "337877666233434";//$_POST['cardNumber'];
$cardExp = "03/2011";//$_POST['ccmonth'] . "/" . substr($_POST["ccyear"],2,2);
$cvdIndicator = "111";//$_POST['cvdIndicator'];
$cvdValue = "111";//$_POST['cvdValue'];
$issueNumber = "111";//$_POST['issueNumber'];
$cardType = "VI";//$_POST['cardType'];


$testRead = "<?xml version='1.0' encoding='UTF-8'?>
<EngineDocList>
<DocVersion>1.0</DocVersion>
<EngineDoc>
    <ContentType>OrderFormDoc</ContentType>
    <User>
        <Name>xxx</Name>
        <Password>xxx</Password>
        <ClientId>xxx</ClientId>        
    </User>
    <Instructions>
        <Pipeline>PaymentNoFraud</Pipeline>
    </Instructions>
    <OrderFormDoc>
        <Mode>P</Mode>
        <Comments/>
        <Consumer>
            <Email/>
            <PaymentMech>
                <CreditCard>
                    <Number>".$cardNumber."</Number>
                    <Expires DataType='ExpirationDate' Locale='840'>".$cardExp."</Expires>
                    <Cvv2Val>".$cvdValue."</Cvv2Val>
                    <Cvv2Indicator>".$cvdIndicator."</Cvv2Indicator>
                    <IssueNum>".$issueNumber."</IssueNum>
                </CreditCard>
            </PaymentMech>
        </Consumer>
        <Transaction>
            <Type>Auth</Type>
            <CurrentTotals>
                <Totals>
                    <Total DataType='Money' Currency='826'>".$amount."</Total>
                </Totals>
            </CurrentTotals>
        </Transaction>
    </OrderFormDoc>
</EngineDoc>
    </EngineDocList>";
?>
<?php


//$url = "https://www.uat.apixml.netq.hsbc.com";
$url = "https://www.secure-epayments.apixml.hsbc.com/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$testRead);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,  2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$result_tmp = curl_exec ($ch);
curl_close ($ch);
///////////////////////////////////////
// use XML Parser result
   $xml_parser = xml_parser_create();
   xml_parser_set_option($xml_parser,XML_OPTION_CASE_FOLDING,0);
   xml_parser_set_option($xml_parser,XML_OPTION_SKIP_WHITE,1);
   xml_parse_into_struct($xml_parser, $result_tmp, $vals, $index);
   xml_parser_free($xml_parser);    

//print_r($vals);  // print all the arrays.
//print_r($vals[29]); // print only the selected array.
$val1 = $vals[21];
// ProcReturnMsg
$paymentResult = $val1[value];


$result_tmp = "";
$k=0;
$findthis = false;
$findthis2 = false;
foreach ($vals as $val) {
$result_tmp.= $k."{"; 
foreach($val as $d => $a) {
      $result_tmp.="[".$d."]".$a;
      if($d=="tag" && $a=="TransactionStatus"){
          $findthis = true;
      }
      if($d=="value" && $findthis){
          $tResult = $a;
          $findthis = false;
      }

      if($d=="tag" && $a=="Text"){
          $findthis2 = true;
      }
      if($d=="value" && $findthis2){
          $tResult2 = $a;
          $findthis2 = false;
      }

}  
$result_tmp.= "}"; 
$k++; 

} 


echo $tResult2.$tResult;

?>

以下是其中一个网站无法运行的示例 gs.net输出是:付款处理...收到的 HTTP 方法无效.只接受 POST.

Here is an example of one of the sites not working gs.net The output is: payment processing... The HTTP method received is not valid. Only POST is accepted.

而当我将这个完全相同的文件上传到我的其他一些网络主机时,例如:HGL 工作示例这里的输出是支付处理...无法确定卡类型.('长度' 是 '15')E这听起来像是一个错误信息,但基本上那个错误并不重要,所以后者是我们在第一个链接中试图实现的.

Whereas when I upload this exact same file to some of my other web hosts such as: HGL working example The output here is payment processing... Unable to determine card type. ('length' is '15')E This sounds like an error message, but basically that error is not important, so the latter is what we are trying to achieve in the first link.

我什至已将此文件上传到我的一些非常基本的主机帐户,有时它会工作有时不会,所以我猜这与托管公司允许或已打开/关闭的内容有关.

I have even uploaded this file to some really basic hosting accounts of mine, sometimes it will work sometimes it won't, so I'm guessing it's something to do with what the hosting company are allowing or have switched On/Off.

有什么想法吗?

谢谢

推荐答案

这似乎是由于应用到服务器的 PHP 升级引起的,这让我发疯了.

This seems to have been caused by a PHP upgrade applied to the server and it was driving me crazy.

解决方案是在指定 CURL 连接时设置以下 SSL 选项.

The solution is to set the following SSL options when specifying the CURL connection.

curl_setopt($ch, CURLOPT_SSLVERSION, 3);
curl_setopt($ch, CURLOPT_SSL_CIPHER_LIST, 'RC4-MD5');

这篇关于收到的 HTTP 方法无效.只接受 POST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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