使用curl加载xsl页面返回实际的基数错误
我们有一个 DITA XML 应用程序,它可以动态生成 xhtml,并且在浏览器中查看时它看起来很好。
如果我尝试使用加载网址我得到以下错误:
Error checking function parameter 3 in call transform:transform($fDoc, LiveContent-UI:get_xsl("ui/ui_skin.xsl", ""), LiveContent-UI:get_xsl_params(untyped-value-check[xs:string, $skin], $extra_params)): The actual cardinality for parameter 1 does not match the cardinality declared in the function's signature: LiveContent-Util:browser_from_user_agent($a as xs:string) xs:string. Expected cardinality: exactly one, got 0.
XQuery Stack TraceLiveContent-Util:browser_from_user_agent(xs:string) 161:55
LiveContent-UI:get_xsl_params(xs:string, node()) 145:25
LiveContent-UI:get_html(xs:string, xs:string, node(), node()) 313:25
LiveContent-Pub:home(xs:string, xs:string, xs:string) 65:17
Java Stack Trace:Class Name Method Name File Name Line
org.exist.xquery.DynamicCardinalityCheck eval DynamicCardinalityCheck.java 80
org.exist.xquery.Atomize eval Atomize.java 66
org.exist.xquery.UntypedValueCheck eval UntypedValueCheck.java 75
org.exist.xquery.DynamicTypeCheck eval DynamicTypeCheck.java 61
org.exist.xquery.FunctionCall eval FunctionCall.java 185
org.exist.xquery.AbstractExpression eval AbstractExpression.java 61
org.exist.xquery.PathExpr eval PathExpr.java 241
org.exist.xquery.AttributeConstructor eval AttributeConstructor.java 95
org.exist.xquery.ElementConstructor eval ElementConstructor.java 212
org.exist.xquery.AbstractExpression eval AbstractExpression.java 61
org.exist.xquery.PathExpr eval PathExpr.java 241
org.exist.xquery.ElementConstructor eval ElementConstructor.java 271
org.exist.xquery.AbstractExpression eval AbstractExpression.java 61
org.exist.xquery.PathExpr eval PathExpr.java 241
org.exist.xquery.DebuggableExpression eval DebuggableExpression.java 56
org.exist.xquery.DebuggableExpression eval DebuggableExpression.java 63
org.exist.xquery.LetExpr eval LetExpr.java 208
org.exist.xquery.BindingExpression eval BindingExpression.java 158
org.exist.xquery.AbstractExpression eval AbstractExpression.java 61
org.exist.xquery.PathExpr eval PathExpr.java 241
并且我完全不知道出了什么问题。
PHP Curl 代码如下:
$ch = curl_init();
/**
* Set the URL of the page or file to download.
*/
curl_setopt($ch, CURLOPT_URL, 'http://onlineservices.letterpart.com/sitemap.xml;jsessionid=1j1agloz5ke7l?id=1j1agloz5ke7l');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec ($ch);
curl_close ($ch);
$xml = new SimpleXMLElement($data);
foreach ($xml->url as $url_list) {
$url = $url_list->loc;
echo $url ."<br>";
//file_get_contents($url);
echo $url ."<br>";
$ch = curl_init($url); //load the urls
echo $url ."<br>";
curl_setopt($ch, CURLOPT_TIMEOUT_m2, 20); //No need to wait for it to load. Execute it and go.
curl_exec($ch); //Execute
curl_close($ch); //Close it off
有人可以帮忙吗?我有点不知所措,因为这超出了我的技能范围。
谢谢,
编辑:
有人建议我添加一个用户代理,因此我添加了以下内容:
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (兼容; MSIE 5.01; Windows NT 5.0)");
现在,我的日志中出现以下错误:
[13-May-2011 16:30:14] PHP Notice: Use of undefined constant CURLOPT_TIMEOUT_m2 - assumed 'CURLOPT_TIMEOUT_m2' in /home/digital1/public_html/dev/sitemap.php on line 43
[13-May-2011 16:30:14] PHP Warning: curl_setopt() [<a href='function.curl-setopt'>function.curl-setopt</a>]: Invalid curl configuration option in /home/digital1/public_html/dev/sitemap.php on line 43
这里有问题的两行 (43) 是:
curl_setopt($ch, CURLOPT_TIMEOUT_m2, 20); //No need to wait for it to load. Execute it and go.
我使用 Googlebot 代理似乎确实有更好的运气:
Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)
正如我实际上正在将内容写入屏幕,但我的日志仍然是显示这些错误。
we have a DITA XML application that produces on the fly xhtml and when viewed in the browser it looks fine.
An example url is: http://livecontent.jordanpublishing.co.uk/content/en/FAMILY-201103311115/Family_FLJONLINE_FLJ_2009_07_4
If I try to load the url using curl I get the following error:
Error checking function parameter 3 in call transform:transform($fDoc, LiveContent-UI:get_xsl("ui/ui_skin.xsl", ""), LiveContent-UI:get_xsl_params(untyped-value-check[xs:string, $skin], $extra_params)): The actual cardinality for parameter 1 does not match the cardinality declared in the function's signature: LiveContent-Util:browser_from_user_agent($a as xs:string) xs:string. Expected cardinality: exactly one, got 0.
XQuery Stack TraceLiveContent-Util:browser_from_user_agent(xs:string) 161:55
LiveContent-UI:get_xsl_params(xs:string, node()) 145:25
LiveContent-UI:get_html(xs:string, xs:string, node(), node()) 313:25
LiveContent-Pub:home(xs:string, xs:string, xs:string) 65:17
Java Stack Trace:Class Name Method Name File Name Line
org.exist.xquery.DynamicCardinalityCheck eval DynamicCardinalityCheck.java 80
org.exist.xquery.Atomize eval Atomize.java 66
org.exist.xquery.UntypedValueCheck eval UntypedValueCheck.java 75
org.exist.xquery.DynamicTypeCheck eval DynamicTypeCheck.java 61
org.exist.xquery.FunctionCall eval FunctionCall.java 185
org.exist.xquery.AbstractExpression eval AbstractExpression.java 61
org.exist.xquery.PathExpr eval PathExpr.java 241
org.exist.xquery.AttributeConstructor eval AttributeConstructor.java 95
org.exist.xquery.ElementConstructor eval ElementConstructor.java 212
org.exist.xquery.AbstractExpression eval AbstractExpression.java 61
org.exist.xquery.PathExpr eval PathExpr.java 241
org.exist.xquery.ElementConstructor eval ElementConstructor.java 271
org.exist.xquery.AbstractExpression eval AbstractExpression.java 61
org.exist.xquery.PathExpr eval PathExpr.java 241
org.exist.xquery.DebuggableExpression eval DebuggableExpression.java 56
org.exist.xquery.DebuggableExpression eval DebuggableExpression.java 63
org.exist.xquery.LetExpr eval LetExpr.java 208
org.exist.xquery.BindingExpression eval BindingExpression.java 158
org.exist.xquery.AbstractExpression eval AbstractExpression.java 61
org.exist.xquery.PathExpr eval PathExpr.java 241
and I am completely at a loss as to what is going wrong.
The PHP Curl code is as follows:
$ch = curl_init();
/**
* Set the URL of the page or file to download.
*/
curl_setopt($ch, CURLOPT_URL, 'http://onlineservices.letterpart.com/sitemap.xml;jsessionid=1j1agloz5ke7l?id=1j1agloz5ke7l');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec ($ch);
curl_close ($ch);
$xml = new SimpleXMLElement($data);
foreach ($xml->url as $url_list) {
$url = $url_list->loc;
echo $url ."<br>";
//file_get_contents($url);
echo $url ."<br>";
$ch = curl_init($url); //load the urls
echo $url ."<br>";
curl_setopt($ch, CURLOPT_TIMEOUT_m2, 20); //No need to wait for it to load. Execute it and go.
curl_exec($ch); //Execute
curl_close($ch); //Close it off
Can anyone help? I'm at a bit of a loss as this is way outside of my skill set.
Thanks,
EDIT:
It was suggested that I added a User Agent so I added the following:
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
I now get the following error in my logs:
[13-May-2011 16:30:14] PHP Notice: Use of undefined constant CURLOPT_TIMEOUT_m2 - assumed 'CURLOPT_TIMEOUT_m2' in /home/digital1/public_html/dev/sitemap.php on line 43
[13-May-2011 16:30:14] PHP Warning: curl_setopt() [<a href='function.curl-setopt'>function.curl-setopt</a>]: Invalid curl configuration option in /home/digital1/public_html/dev/sitemap.php on line 43
The two line in question here (43) is:
curl_setopt($ch, CURLOPT_TIMEOUT_m2, 20); //No need to wait for it to load. Execute it and go.
I do seem to be having better luck using the Googlebot agent:
Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)
as in I am actually getting content written to the screen but my logs are still showing these errors.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的直接猜测是您的 Java 应用程序期望设置
User-Agent
标头。由于 Curl 默认情况下不发送User-Agent
标头,因此您需要设置一个。尝试将其添加到设置CURL_TIMEOUT_m2
的选项上方。如果由于某种原因它不喜欢该
User-Agent
字符串,您可能需要尝试使用实际浏览器中的字符串。编辑:
根据您的编辑,这是因为您输入了curl超时常量。它应该是
CURLOPT_TIMEOUT_MS
而不是CURLOPT_TIMEOUT_m2
。My immediate guess is that your Java app is expecting the
User-Agent
header to be set. Since Curl does not send aUser-Agent
header by default, you will need to set one. Try adding this above your option to setCURL_TIMEOUT_m2
.If for some reason it does not like that
User-Agent
string, you might want to try using one from an actual browser.EDIT:
Per your edit, this is because you've typoed the curl timeout constant. It should be
CURLOPT_TIMEOUT_MS
notCURLOPT_TIMEOUT_m2
.