尝试cURL时“ /”应用程序中的服务器错误 [英] Server Error in '/' Application when attempting to cURL

查看:41
本文介绍了尝试cURL时“ /”应用程序中的服务器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用cURL下载pdf,并被卡在应用程序中的服务器错误页面上。我的代码:

I am trying to download a pdf using cURL and am getting stuck on a "Server Error in '/' Application" page. My code:

$url = "https://some.domain.com/Reports/Report?ReportID=123456"
$ch = curl_init($url);
$header = array ('Host: some.domain.com');

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.76 Safari/537.36');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSLVERSION, 4);
curl_setopt($ch, CURLOPT_SSL_CIPHER_LIST, implode(':', $arrayCiphers));
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);

curl_setopt($ch, CURLOPT_COOKIE, "ASP.NET_SessionId=XXXXXXXX; __RequestVerificationToken_XXXXXXX=lots-of-alpha-numeric-characters");
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt");

curl_setopt($ch, CURLOPT_REFERER, "https://some.domain.com");

$output = curl_exec($ch);
echo $output;
curl_close($ch);

还有其他可以尝试的方法吗?还是可以进行更多调试?

Is there something else I can try or some more debugging I can do?

[edit] 显然是由我的参数之一引起的。 URL中有几个参数。 & Flag = True 似乎是导致错误的原因。如果将其更改为& Flag = False ,我会得到一个空白页。

[edit] Apparently it's caused by one of my parameters. There are several parameters in the URL. &Flag=True seems to be causing the error. If I change it to &Flag=False I get a blank page.

推荐答案

之所以引起此错误,是因为我的curl请求标头不包含下载文件所需的cookie。在标题中添加这些cookie即可解决该问题。

This error was being caused because my curl request header did not include cookies that were required to download the file. Adding those cookies in the header fixed it.

这篇关于尝试cURL时“ /”应用程序中的服务器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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