- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我的代码如下所示,但我无法成功获得响应。我的代码有什么问题吗?
代码:
$headers = array('Content-Type: text/xml;charset=UTF-8','Content-Encoding: gzip',);
$gziped_xml_content = gzencode($xml_content);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $the_web_service_url);
curl_setopt($ch, CURLOPT_TIMEOUT,120);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
curl_setopt($ch, CURLOPT_POSTFIELDS, $gziped_xml_content);
$res = curl_exec($ch);
curl_close($ch);
最佳答案
代码是正确的。我的意思是 curl 没问题。错误在别处。您的代码返回以下 verbose
输出,这意味着代码是正确的。
Accept-Encoding: gzip
Content-Type: text/xml;charset=UTF-8
Content-Encoding: gzip
Content-Length: XXX <- some digits
场景#1:可能是服务器无法处理 gzip 数据。所以它会向您抛出错误。
场景#2:可能是您发送的 XML 格式不正确,服务器无法解析它并向您抛出错误。
场景#3:可能是您发送的数据对于正常的 curl 帖子而言太大(内容长度 > 1024)。在这种情况下,您必须使用 multipart/form-data
表单发布。
但在此之前,请在启用 VERBOSE 模式的情况下运行 curl 代码,这将帮助您自行调试。
curl_setopt($ch, CURLOPT_VERBOSE, 1);
最后,I cannot get the response successfully
在您的问题中不是一个好的观点。与其使用你正在相处的错误,还有更多有问题的信息,这将有助于其他想要帮助你的人!
关于php - 如何使用 curl 和 php 发送 gziped xml 内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22554008/
我最近在此 Thoughtbot blog post 之后在我的 Rails 4 应用程序上启用了 GZIP我还添加了 use Rack::Deflater按照 this post 的建议添加到我的
我想知道 nginx 是否可以将 gzip 压缩的内容保存在缓存中,或者它一直 gzip 文件? 通过“保留缓存”,我的意思是内存或磁盘中的某些东西,在服务器端(没有浏览器缓存)。 因为我看到静态压缩
我试图让一段打开 http 连接的代码工作。然而,网页可以以纯文本或 gzip 格式传输。因此,具有实用主义的代码会尝试以纯文本形式打开,如果失败并接收到异常,则尝试使用 gzip 编码。 URL 是
我需要向 Web 服务器发送 POST 请求,并能够读取该服务器发送的响应。 我尝试使用带有以下代码的 HTTPBuilder 库: def http = new HTTPBuilder('http:
我的代码如下所示,但我无法成功获得响应。我的代码有什么问题吗? 代码: $headers = array('Content-Type: text/xml;charset=UTF-8','Content
我正在尝试做一个接受压缩响应的请求 var request = (HttpWebRequest)HttpWebRequest.Create(requestUri); request.Headers.A
这是我尝试过的随机顺序的列表: AddHandler application/x-httpd-php .otf AddType default_mimetype auto_prepend_file =
我启用了 Amazon CloudFront gzip 功能:“Compress Objects Automatically”。 我的 CloudFront 中的所有文件都会发生这种情况,而其他 CS
为什么 IE 10 和 11 无法加载 GZiped 内容(js 和 css)?当我从支持 gzip 压缩的服务器加载页面时,IE 加载第一个 HTML 页面但无法加载其他 js 和 css 文件。在
我是一名优秀的程序员,十分优秀!