如何使用PHP curl命令行发送标题? [英] How to send header using PHP curl command line?
本文介绍了如何使用PHP curl命令行发送标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用curl将XML发布到Web服务。代码如下:
I am using curl to post XML to a webservice. The code is below:
exec("/usr/bin/curl -s -m 120 -d \"$xml\" $URL -L", $return_message_array, $return_number);
我要添加此自定义标题:
I want to add this custom header to it:
$headers = array(
"Content-type: application/soap+xml; charset=utf-8",
"SOAPAction: http://loantree.com/webservices/InsertLead",
);
我试过:
exec("/usr/bin/curl -s -m 120 -H $headers -d \"$xml\" $URL -L", $return_message_array, $return_number);
但这只是返回我试图发布的页面。有没有人知道如何实现这个?
But that just returns the page I'm trying to post to. Does anyone know how I can achieve this?
推荐答案
curl
选项,可以多次使用:
Headers for curl
are set with the -H
option, which can be used multiple times:
curl -H "Header-1: Value" -H "Header-2: Value" http://example.com
注意 PHP有一个 curl库。所以你不必使用 exec()
。
Note: If installed, PHP has a curl library. So you don't have to use exec()
.
这篇关于如何使用PHP curl命令行发送标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文