如何使用curl和php发送压缩的xml内容 [英] How to send gziped xml content using curl and php

查看:180
本文介绍了如何使用curl和php发送压缩的xml内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码如下所示,但是我无法成功获得响应。我的代码有什么问题吗?

My code like that as below, but I cannot get the response successfully. Is anything wrong with my code?

代码:

$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);


推荐答案

代码正确。我的意思是卷曲没有问题。该错误在其他地方。您的代码将在详细输出之后返回,这表明代码正确。

The code is correct. I mean the curl is ok. The error is elsewhere. Your code returns following verbose output which implies the code is correct.

Accept-Encoding: gzip
Content-Type: text/xml;charset=UTF-8
Content-Encoding: gzip
Content-Length: XXX <- some digits

方案#1 :可能是服务器无法处理gzip数据。

Scenario#1: It can be the server can not handle gzip data. So its throwing you error.

场景#2 :可能是您发送的XML格式不正确,服务器无法解析它并抛出错误。

Scenario#2: May be the XML you are sending that has incorrect format, and server failed to parse it and throw you error.

场景#3 :可能是您发送的数据太大(内容长度> 1024),对于正常情况卷曲的职位。在这种情况下,您必须使用 multipart / form-data 表单发布。

Scenario#3: May be the data you are sending its too large(content length > 1024) for a normal curl post. That case you have to use multipart/form-data form posting.

但是在执行任何操作之前,请运行curl代码

But before anything, run the curl code with VERBOSE mode enable and it will help you to debug this yourself.

curl_setopt($ch, CURLOPT_VERBOSE, 1);

最后,我无法成功获得响应在您的问题中不是一个好主意。宁可使用错误来解决更多问题信息,也将帮助想要帮助您的其他人!

Finally, I cannot get the response successfully is not a good point to make in your question. Rather using the error you are getting along with more problematic info will help the others who want to help you!

这篇关于如何使用curl和php发送压缩的xml内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆