问题 使用 PHP 在 obiee wsdl url 上下载 xlsx 文件

问题描述

我可以从 WSDL 链接下载手册文件。我该怎么做才能用 PHP 自动下载这个。

<?PHP

$fileUrl = 'https://xxxx/analytics/saw.dll?Go&NQUser=XXXX&NQPassword=XXXXX&ViewState=qo6q974d3geeipbev3hv9gdnbm&Action=Download&path=/shared/XXXXX&Format=excel2007&Extension=.xlsx';
 $agents = array(
    'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:7.0.1) Gecko/20100101 Firefox/7.0.1','Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.9) Gecko/20100508 SeaMonkey/2.0.4','Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)','Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; da-dk) AppleWebKit/533.21.1 (KHTML,like Gecko) Version/5.0.5 Safari/533.21.1'
 
);
 $header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,";
    $header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
    $header[] = "Cache-Control: max-age=0";
    $header[] = "Connection: keep-alive";
    $header[] = "Keep-Alive: 300";
    $header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
    $header[] = "Accept-Language: en-us,en;q=0.5";
    $header[] = "Pragma: ";
//The path & filename to save to.
$saveto = 'file.xlsx';
 
//Open file handler.
$fp = fopen($saveto,'w+');
 
//If $fp is FALSE,something went wrong.
if($fp === false){
    throw new Exception('Could not open: ' . $saveto);
}
 
//Create a cURL handle.
$ch = curl_init($fileUrl);
 
curl_setopt($ch,CURLOPT_USERAGENT,$agents[array_rand($agents)]);
curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
//Pass our file handle to cURL.
curl_setopt($ch,CURLOPT_FILE,$fp);
curl_setopt($ch,CURLOPT_HEADER,true);
curl_setopt($ch,CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_0);
 
//Timeout if the file doesn't download after 20 seconds.
curl_setopt($ch,CURLOPT_TIMEOUT,20);
 
//Execute the request.
curl_exec($ch);
 
//If there was an error,throw an Exception
if(curl_errno($ch)){
    throw new Exception(curl_error($ch));
}
 
//Get the HTTP status code.
$statusCode = curl_getinfo($ch,CURLINFO_HTTP_CODE);
 
//Close the cURL handler.
curl_close($ch);
 
//Close the file handler.
fclose($fp);
 
if($statusCode == 200){
    echo 'Downloaded!';
} else{
    echo "Status Code: " . $statusCode;
}

HTTP/1.1 505 不支持 HTTP 版本 服务器不支持或拒绝支持请求消息中使用的 HTTP 协议版本。服务器表明它无法或不愿意使用与客户端相同的主要版本来完成请求,如第 3.1 节所述,除了此错误消息。响应应该包含一个实体,描述为什么不支持该版本以及该服务器支持哪些其他协议。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)