PHP Curl的行为不像命令行Curl

I've posted XML to a server via the command line curl and I've been completely successful. The only option I'm actually setting is the a header to set the content-type to application/xml.

When I turn around and try this in PHP I'm getting a 500 server error.

As far as curl options all I'm setting are as follows:

curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
curl_setopt($curl, CURLOPT_POSTFIELDS, $request);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

I've even gone so far as to copy and paste the XML output from the PHP application into the command line curl and it works just fine. I've tried various other curl options in different combinations with no luck.

If I had to guess there is some kind of encoding issue that is occurring but I've tried urlencoding the data and I actually get back a bad request instead of the 500.

I'm at a complete loss so if anyone has any ideas I'd love to hear them.

Thanks!

#0

Try to modify the content-type option from:

curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));

to :

curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));

#1

It's worth noting that the cURL PHP has installed doesn't have to be the same version as the one you have installed on you server. Check to see what version you have installed on CLI ($ curl --version) and then check PHP with something like <?php phpinfo();.

#2

The problem was not PHP. I was not paying close attention to the error output from the server. Command line curl was failing at the same place every time due to a database constraint on a transaction id but was actually displaying the expected output causing me to think it was working correctly.

PHP, which was using the current hour, minute, second for the transaction id was getting past the point of failure in the command line and failing at a null value, which was actually a problem with my XML. The problem was the null value is an unhandled exception in the code on the remote server so the response back left me thinking something else had gone wrong.

Thanks for the help and sorry about the wild goose chase.

推荐文章

什么是实体框架fluent api?

什么是实体框架fluent api?

推荐文章

Python:创建特殊类型的子类type(例如“int列表”)

Python:创建特殊类型的子类type(例如“int列表”)

推荐文章

Sugar CRM在电子邮件中显示变量而不是值

Sugar CRM在电子邮件中显示变量而不是值

推荐文章

选择与另一个成功聚合函数匹配的列的值的聚合函数

选择与另一个成功聚合函数匹配的列的值的聚合函数

推荐文章

预填文本表单

预填文本表单

推荐文章

在CakePHP中删除之前检查它是否有相关项

在CakePHP中删除之前检查它是否有相关项

推荐文章

fopen/fclose上的Seg故障

fopen/fclose上的Seg故障

推荐文章

停止后启动动画

停止后启动动画

推荐文章

如何将列表从JSP传递到ACtion类

如何将列表从JSP传递到ACtion类

推荐文章

找到只有引用指针的对象数组的总大小?

找到只有引用指针的对象数组的总大小?

推荐文章

WM_KEYDOWN-捕获导致事件的按键

WM_KEYDOWN-捕获导致事件的按键

推荐文章

递归查找记录历史以找到所需的记录

递归查找记录历史以找到所需的记录

推荐文章

编码功能允许空间(Sage ShiftCryptosystem)

编码功能允许空间(Sage ShiftCryptosystem)

推荐文章

Hello world文件恢复示例?

Hello world文件恢复示例?

推荐文章

如何下载椰子树杰克?

如何下载椰子树杰克?

推荐文章

为什么某些区域设置中没有正确填充Spring消息源参数?

为什么某些区域设置中没有正确填充Spring消息源参数?