TCPDF我无法从另一个页面获取html,比如index.php?something = something

时间:2022-08-23 10:29:06

I am struggling to create a pdf file with tcpdf from a dynamically generated page.

我正在努力用动态生成的页面创建一个带有tcpdf的pdf文件。

My problem is that I've got a logging session and when accessing the file it gets only the credentials if you're not logged in.

我的问题是我有一个日志记录会话,当访问该文件时,如果你没有登录,它只获取凭据。

So my bit for collecting the html is:

所以我收集html的一点是:

$curl_handle=curl_init();
curl_setopt($curl_handle, CURLOPT_URL,'http://www.domain.com/subdir/index.php?something=ref');
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_USERAGENT, 'Your application name');
$html = curl_exec($curl_handle);
curl_close($curl_handle);

So what I've got after running it, is 'HTTP Error 401: - Unauthorised'.

所以我在运行它后得到的是'HTTP Error 401: - Unauthorized'。

I hope my explanation makes sense.

我希望我的解释是有道理的。

Any help will be much appreciated!

任何帮助都感激不尽!

1 个解决方案

#1


0  

I had the same issue while working with PDF using TCPDF where in curl CURLOPT_USERAGENT was TCPDF like below.

使用TCPDF处理PDF时遇到了同样的问题,其中curl CURLOPT_USERAGENT是TCPDF,如下所示。

curl_setopt($curl_handle, CURLOPT_USERAGENT, 'TCPDF');

I just commented this line and try to generate pdf and it worked.

我只是评论了这一行并尝试生成pdf并且它有效。

I know this is not a proper way but it worked for me.

我知道这不是一个正确的方法,但它对我有用。

#1


0  

I had the same issue while working with PDF using TCPDF where in curl CURLOPT_USERAGENT was TCPDF like below.

使用TCPDF处理PDF时遇到了同样的问题,其中curl CURLOPT_USERAGENT是TCPDF,如下所示。

curl_setopt($curl_handle, CURLOPT_USERAGENT, 'TCPDF');

I just commented this line and try to generate pdf and it worked.

我只是评论了这一行并尝试生成pdf并且它有效。

I know this is not a proper way but it worked for me.

我知道这不是一个正确的方法,但它对我有用。