Zend_Http_Client 和 cURL 正在删除换行符
我正在尝试从远程服务器获取 CSV 文件并使用 Zend_Http_Client 下载
它 获取的版本已删除所有换行符。
require_once('Zend/Http/Client.php');
$client = new Zend_Http_Client($url);
//also tried the curl adapter but no change
$client->setCookieJar();
$client->setAuth('user', 'pass', Zend_Http_Client :: AUTH_BASIC);
if(!empty($params)){
$client->setParameterGet($params);
}
$client->request();
$request = $client->getLastRequest();
$response = $client->getLastResponse();
echo $response->getRawBody();
响应全是一行。
如果我使用curl 获取$url
,它会位于不同的行上。
另外,我正在查看源代码,而不是 HTML 渲染版本
UPDATE
所以我使用 cURL 重写了该位,但它仍然做同样的事情!?
if(!empty($params)){
$queryString = http_build_query($params);
$url.='?'.$queryString;
}
$ch = curl_init($url);
curl_setopt($ch,CURLOPT_USERPWD,"$username:$password");
curl_exec($ch);
任何想法
I'm trying to fetch a CSV file from a remote server and download it Using Zend_Http_Client
The fetched version has all of the newlines removed.
require_once('Zend/Http/Client.php');
$client = new Zend_Http_Client($url);
//also tried the curl adapter but no change
$client->setCookieJar();
$client->setAuth('user', 'pass', Zend_Http_Client :: AUTH_BASIC);
if(!empty($params)){
$client->setParameterGet($params);
}
$client->request();
$request = $client->getLastRequest();
$response = $client->getLastResponse();
echo $response->getRawBody();
The response is all one line.
If I fetch the $url
with curl it is on separate lines.
Also, I am looking at the source, not the HTML rendered version
UPDATE
So I rewrote that bit using cURL and it still does the same thing !?
if(!empty($params)){
$queryString = http_build_query($params);
$url.='?'.$queryString;
}
$ch = curl_init($url);
curl_setopt($ch,CURLOPT_USERPWD,"$username:$password");
curl_exec($ch);
Any ideas
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为什么使用 getRawBody() 而不是 getBody()? rawBody() 通常不是您想要的,并且可能以某种形式进行编码。
无论如何,您可以发布从服务器获得的响应标头吗?另外,指向实际文件或其中几行的链接也会有所帮助。
Why are you using getRawBody() and not getBody()? rawBody() is usually not the one you want, and might be encoded in some form.
In any case can you post the response headers you get from the server? Also a link to the actual file or a few lines of it would help.
这并不是真正的答案,但解决方法是使用curl 系统调用。
看起来这是行结尾的问题,即使我设置了 ini 值,它们也没有被检测到。
Not really an answer, but a work around is to use the curl system call.
It looks like it is an issue with the line endings, they aren't getting detected even when I set the ini value.
您可以尝试使用 cURL 适配器设置 Zend_Http_Client 吗:
另外,您确定您没有在浏览器中显示
$response->getRawBody()
吗?浏览器将其解释为 HTML,因此将换行符解释为空格?如果您右键单击-> 显示来源,你有换行符吗?
Can you try to setup Zend_Http_Client with the cURL adapter:
Also, are you sure you're not displaying
$response->getRawBody()
in your browser, which interprets it as HTML, therefore interpreting newlines as spaces?If you right click -> show source, do you have the newlines?