简体   繁体   English

发送包含PHP + cURL的gpg签名的XML文件

[英]Sending an XML file contains gpg signature with PHP+cURL

I have an xml file and a GPG signature is in it, in <SIGNATURE> tag. 我在<SIGNATURE>标记中有一个xml文件和一个GPG签名。

Here is the xml: 这是xml:

$xml = "<DATA>
 ....
  <SIGNATURE>-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (GNU/Linux)

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxx

-----END PGP SIGNATURE-----
  </SIGNATURE>
</DATA>";

When I send this xml with perl, the respond is ok and remote host accepts the signature. 当我使用perl发送此xml时,响应正常,并且远程主机接受签名。

But if I send this xml with php and cURL, remote server will dismiss the signature. 但是,如果我使用php和cURL发送该xml,则远程服务器将关闭该签名。

The next modules are used in perl script: use URI (); use GnuPG qw( :algo ); use LWP::UserAgent (); use IO::Socket::SSL; 接下来的模块在perl脚本中use URI (); use GnuPG qw( :algo ); use LWP::UserAgent (); use IO::Socket::SSL;use URI (); use GnuPG qw( :algo ); use LWP::UserAgent (); use IO::Socket::SSL; use URI (); use GnuPG qw( :algo ); use LWP::UserAgent (); use IO::Socket::SSL;

Next cURL options are set in the php script: 接下来的cURL选项在php脚本中设置:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_RETURNTRANSFER  ,1);

I guess there is problem with curl ....Probably a curl setting is missed, but I don't know which. 我想卷曲有问题。可能缺少卷曲设置,但我不知道是哪个。 I have tried urlencode , qoutemeta php functions for $xml string, but no results. 我已经尝试了$xml字符串的urlencodeqoutemeta php函数,但是没有结果。

Add user agent option. 添加用户代理选项。
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.1) Gecko/2008070206 Firefox/3.0.1"); curl_setopt($ ch,CURLOPT_USERAGENT,“ Mozilla / 5.0(Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.1)Gecko / 2008070206 Firefox / 3.0.1”);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ ch,CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ ch,CURLOPT_URL,$ url);
curl_setopt($ch, CURLOPT_POST,1); curl_setopt($ ch,CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); curl_setopt($ ch,CURLOPT_POSTFIELDS,$ xml);
curl_setopt($ch, CURLOPT_RETURNTRANSFER ,1); curl_setopt($ ch,CURLOPT_RETURNTRANSFER,1);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM