laravel 尝试执行 CURL 时出现 500 内部服务器错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32830923/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 12:25:03  来源:igfitidea点击:

500 internal server error when trying to execute CURL

.htaccesslaravelcurl

提问by user3718908

Hello i am having an issue here, i get a 500 internal server error when i try to execute curl on my server. I contacted support and they claim it's my .htaccess file and there is nothing they can do about it.

您好,我在这里遇到了一个问题,当我尝试在我的服务器上执行 curl 时出现 500 内部服务器错误。我联系了支持人员,他们声称这是我的 .htaccess 文件,他们对此无能为力。

This is my code:

这是我的代码:

$api_key = 'f7cb125a449f4f908931f360ac33b52a';
$server_ip = '162.13.170.20';
$port = '5000';
$url = "https://".$server_ip.":".$port."/api/fusion/tp/".$api_key;

// Get cURL resource
$curl = curl_init();
// Set some options - we are passing in a useragent too here
curl_setopt_array($curl, array(
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_URL => $url,
    CURLOPT_USERAGENT => 'myTicketGH',
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => array(
        'kuwaita' => 'malipo',
        'amount' => $calculated_total_cost,
        'mno' => $network,
        'msisdn' => $phone
    )
));
// Send the request & save response to $resp
$resp = curl_exec($curl);
// Close request to clear up some resources
curl_close($curl);

return [
    'response' => $resp
];

And this is my .htaccess file:

这是我的 .htaccess 文件:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    Options +FollowSymLinks
    RewriteEngine on

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteRule . index.php [L]

     RewriteEngine On
     RewriteCond %{HTTP:Authorization} .
     RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

Is there a laravelway of using CURL? Because i can't understand how there can be a problem with my .htaccess file but my application still runs.

是否有使用 CURL的Laravel方式?因为我不明白我的 .htaccess 文件怎么会出现问题,但我的应用程序仍在运行。

I contacted support, apparently this is my error_log:

我联系了支持,显然这是我的错误日志:

[Tue Sep 29 09:31:20 2015] [warn] [client 69.195.125.1] mod_fcgid: read data timeout in 40 seconds
[Tue Sep 29 09:31:20 2015] [error] [client 69.195.125.1] Premature end of script headers: index.php
[Tue Sep 29 09:31:20 2015] [error] [client 69.195.125.1] File does not exist: /home/mytickf1/public_html/500.shtml
[Tue Sep 29 09:31:26 2015] [warn] mod_fcgid: process 14879 graceful kill fail, sending SIGKILL

I should also add that my server uses a dedicated IP address.

我还应该补充一点,我的服务器使用专用 IP 地址。

回答by cre8

You have to handle the https with curl. The easiest option is to turn it off with

您必须使用 curl 处理 https。最简单的选择是关闭它

CURLOPT_SSL_VERIFYPEER => 0

Because if you don't do it you will get an empty result. The 500 error is thrown when you want to work with the result because it is empty.

因为如果你不这样做,你会得到一个空的结果。当您想要处理结果时会抛出 500 错误,因为它是空的。

回答by Azhar

You are using https protocol in your curl URL

您在 curl URL 中使用了 https 协议

$url = "https://".$server_ip.":".$port."/api/fusion/tp/".$api_key;

Should work with http protocol.

应该使用 http 协议。