Curl返回成功,但显示500错误,内部服务器错误

问题描述 投票:1回答:1

我正在使用curl访问Web服务,但有时我得到响应,但有时它会因内部服务器错误而失败,即使我实际收到了预期的xml文件。问题是什么?

$header = array(
                  "Content-type: text/xml;charset=\"utf-8\"",
                  "Accept: text/xml",
                  "Cache-Control: no-cache",
                  "Pragma: no-cache",
                  "Content-length: ".strlen($send),
                );

            $URL = 'https:ip:port/xxxxx';

            $ch = curl_init();
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
            curl_setopt($ch, CURLOPT_TIMEOUT, 120);
            curl_setopt($ch, CURLOPT_URL, $URL );
            curl_setopt($ch, CURLOPT_POST, true );
            curl_setopt($ch, CURLOPT_HTTPHEADER, $header); //array('Content-Type: text/xml'));
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
            curl_setopt($ch, CURLOPT_POSTFIELDS, $send );
            //curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
try {
                $result = curl_exec($ch);        
                curl_close($ch);
                $f = fopen("./Response.xml", "w");
                fwrite($f, $result);
                fclose($f);           
            } 
            catch (Exception $e) {
                $payments = "<DIV class = 'alert alert-danger'>Failed Transaction. Please try again</DIV>";
                     $error = Date("Y-m-d h:i:s")."\nError Number:".curl_errno($soap_do)."\n";
                     $error .=  "Error String:".curl_error($ch)."\n Matrucule: ".$matricule."\n------------------------\n";
                     $f = fopen("./Payment_Error_Log.txt", "w");
                     fwrite($f, $error);
                     fclose($f);
            }
php curl soap webservice-client
1个回答
0
投票

你有服务器端代码的问题.. https:ip:port / xxxxx在POST它时返回错误500。

可能是Web服务的问题或您正在发布的特定参数($send)。

© www.soinside.com 2019 - 2024. All rights reserved.