如何发送XML(登录,命令...)请求并获得响应 [英] How to send XML (login, command...) request and get response

查看:74
本文介绍了如何发送XML(登录,命令...)请求并获得响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我正在尝试创建自己的EPP客户端,不知何故我建立了与远程服务器的SSl连接,但现在我无法发送XML登录请求并发送一些XML命令。这是我的代码>>>



Hi
i am trying to create my own EPP Client, somehow i estamblish SSl connection with the remote server but now i cant send XML login request and to send some XML command. Here is my code>>>

<?php

// Hello World! SSL HTTP Server.

// Tested on PHP 5.1.2-1+b1 (cli) (built: Mar 20 2006 04:17:24)

$string = <<<XML

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd"><command><login><clID>VORTECHS-REG</clID>
<pw>8F5ucBeZ7azD7NQ9</pw>
<options><version>1.0</version>
<lang>en</lang>
</options>
<svcs><objURI>http://www.nic.cz/xml/epp/contact-1.6</objURI>
<objURI>http://www.nic.cz/xml/epp/nsset-1.2</objURI>
<objURI>http://www.nic.cz/xml/epp/domain-1.4</objURI>
<objURI>http://www.nic.cz/xml/epp/keyset-1.3</objURI>
<svcExtension><extURI>http://www.nic.cz/xml/epp/enumval-1.2</extURI>
</svcExtension>
</svcs>
</login>

</command>
</epp>
XML;

$infoXML = <<<XML

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd"><command><create><contact:create xmlns:contact="http://www.nic.cz/xml/epp/contact-1.6" xsi:schemaLocation="http://www.nic.cz/xml/epp/contact-1.6 contact-1.6.xsd"><contact:id>VM-1152</contact:id>
<contact:postalInfo><contact:name>Kostdasda</contact:name>
<contact:addr><contact:street>Velasdjko</contact:street>
<contact:city>MK</contact:city>
<contact:pc>2460</contact:pc>
<contact:cc>MK</contact:cc>
</contact:addr>
</contact:postalInfo>
<contact:voice>+389.70898361</contact:voice>
<contact:email>kossdata@gmail.com</contact:email>
<contact:ident type="birthday">25/10/1989</contact:ident>
</contact:create>
</create>
<clTRID>fhsz008#14-11-26at15:33:49</clTRID>
</command>
</epp>


XML;
// Certificate data:
$dn = array(
"countryName" => "UK",
"stateOrProvinceName" => "Somerset",
"localityName" => "Glastonbury",
"organizationName" => "The Brain Room Limited",
"organizationalUnitName" => "PHP Documentation Team",
"commonName" => "Wez Furlong",
"emailAddress" => "wez@example.com"
);



// Generate PEM file
# Optionally change the passphrase from 'comet' to whatever you want,or leave it empty for no passphrase
$pem_passphrase = '5NULtDQ2dBtNPuSP';



$context = stream_context_create();

// local_cert must be in PEM format
stream_context_set_option($context, 'ssl', 'local_cert', './vortechs.pem');
// Pass Phrase (password) of private key
stream_context_set_option($context, 'ssl', 'passphrase', $pem_passphrase);

stream_context_set_option($context, 'ssl', 'allow_self_signed', true);
stream_context_set_option($context, 'ssl', 'verify_peer', false);

// Create the server socket
$server = stream_socket_client('ssl://mk-test.marnet.mk:700', $errno,
$errstr,10, STREAM_CLIENT_CONNECT, $context);

if($server)
{
$xml = simplexml_load_string($string);
$xmll = simplexml_load_string($infoXML);


fwrite($server, $xml);
    while (!feof($server))
    {
        $res = fgets($server, 1024);
        echo htmlEntities($res);
        if (strpos($res, '</OPS_envelope>')) {
            break;
        }
    } echo '<br />';


print('OK');
}



?>





因此我得到的这行不是我需要的那个>





as a result i get this line which is no the one that i need>

;<?xml version="1.0" encoding="UTF-8"?> <epp xmlns="urn:ietf:params:xml:ns:epp-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd"><greeting><svID>EPP server (DSDng)</svID><svDate>2014-11-27T00:44:19+01:00</svDate><svcMenu><version>1.0</version><lang>en</lang><lang>cs</lang><objURI>http://www.nic.cz/xml/epp/contact-1.6</objURI><objURI>http://www.nic.cz/xml/epp/domain-1.4</objURI><objURI>http://www.nic.cz/xml/epp/nsset-1.2</objURI><objURI>http://www.nic.cz/xml/epp/keyset-1.3</objURI><svcExtension><extURI>http://www.nic.cz/xml/epp/enumval-1.2</extURI></svcExtension></svcMenu><dcp><access><all/></access><statement><purpose><admin/><prov/></purpose><recipient><public/></recipient><retention><stated/></retention></statement></dcp></greeting></epp> 
OK







有人可以帮助我吗?




can some one help me?

推荐答案

string = <<<< XML

<?xml version = < span class =code-keyword> 1.0 encoding = utf-8 独立 = >
< epp xmlns = urn:ietf:params:xml:ns:epp-1.0 xmlns:xsi = http://www.w3 .org / 2001 / XMLSchema-instance xsi:schemaLocation = urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd > < 命令 > < login > < clID > VORTECHS-REG < / clID >
< pw > 8F5ucBeZ7azD7NQ9 < / pw >
< options > < version > 1.0 < / version >
< lang > zh_cn < / lang >
< / options >
< svcs > < objURI < span class =code-keyword>> http://www.nic.cz/xml/epp/contact-1.6 < / objURI >
< objURI > http://www.nic.cz/xml/epp/nsset-1.2 < / objURI >
< objURI > http:/ /www.ni c.cz/xml/epp/domain-1.4< / objURI >
< objURI > http://www.nic.cz/xml/epp/keyset-1.3 < / objURI >
< svcExtension > < extURI > http://www.nic.cz/xml/epp/enumval-1.2 < / extURI >
< / svcExtension >
< / svcs >
< / login >

< / command >
< / epp >
XML;
string = <<<XML <?xml version="1.0" encoding="utf-8" standalone="no"?> <epp xmlns="urn:ietf:params:xml:ns:epp-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd"><command><login><clID>VORTECHS-REG</clID> <pw>8F5ucBeZ7azD7NQ9</pw> <options><version>1.0</version> <lang>en</lang> </options> <svcs><objURI>http://www.nic.cz/xml/epp/contact-1.6</objURI> <objURI>http://www.nic.cz/xml/epp/nsset-1.2</objURI> <objURI>http://www.nic.cz/xml/epp/domain-1.4</objURI> <objURI>http://www.nic.cz/xml/epp/keyset-1.3</objURI> <svcExtension><extURI>http://www.nic.cz/xml/epp/enumval-1.2</extURI> </svcExtension> </svcs> </login> </command> </epp> XML;


infoXML = < << XML

<?xml version = 1.0 编码 = utf-8 独立 = no >
< epp xmlns = urn:ietf:params:xml:ns:epp-1.0 xmlns:xsi = http://www.w3 .org / 2001 / XMLSchema-instance xsi:schemaLocation = urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd & gt; < 命令 > < 创建 > < contact:create xmlns:contact = http://www.nic.cz/ xml / epp / contact-1.6 xsi:schemaLocation = http://www.nic.cz/xml/epp/contact-1.6 contact-1.6.xsd > < contact:id > VM-1152 < / c ontact:id >
< contact:postalInfo><contact:name>Kostdasda</contact:name>
<contact:addr><contact:street>Velasdjko</contact:street>
<< span class=\"code-leadattribute\">contact:city
>MK </contact:city>
<contact:pc>2460</contact:pc>
<contact:cc>MK</contact:cc>
</contact:addr>
</contact:postalInfo>
<contact:voice>+389.70898361</contact:voice>
<contact:email>kossdata@gmail.com</contact:email>
<contact:ident type=\"birthday\">25/10/1989</contact:ident>
</c ontact:create>
</create>
<clTRID>fhsz008#14-11-26at15:33:49</clTRID>
</command>
</epp>


XML;
// Certificate data:
infoXML = <<<XML <?xml version="1.0" encoding="utf-8" standalone="no"?> <epp xmlns="urn:ietf:params:xml:ns:epp-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd"><command><create><contact:create xmlns:contact="http://www.nic.cz/xml/epp/contact-1.6" xsi:schemaLocation="http://www.nic.cz/xml/epp/contact-1.6 contact-1.6.xsd"><contact:id>VM-1152</contact:id> <contact:postalInfo><contact:name>Kostdasda</contact:name> <contact:addr><contact:street>Velasdjko</contact:street> <contact:city>MK</contact:city> <contact:pc>2460</contact:pc> <contact:cc>MK</contact:cc> </contact:addr> </contact:postalInfo> <contact:voice>+389.70898361</contact:voice> <contact:email>kossdata@gmail.com</contact:email> <contact:ident type="birthday">25/10/1989</contact:ident> </contact:create> </create> <clTRID>fhsz008#14-11-26at15:33:49</clTRID> </command> </epp> XML; // Certificate data:


dn = array(
\"countryName\" => \"UK\",
\"stateOrProvinceName\" => \"Somerset\",
\"localityName\" => \"Glastonbury\",
\"organizationName\" => \"The Brain Room Limited\",
\"organizationalUnitName\" => \"PHP Documentation Team\",
\"commonName\" => \"Wez Furlong\",
\"emailAddress\" => \"wez@example.com\"
);



// Generate PEM file
# Optionally change the passphrase from 'comet' to whatever you want,or leave it empty for no passphrase
dn = array( "countryName" => "UK", "stateOrProvinceName" => "Somerset", "localityName" => "Glastonbury", "organizationName" => "The Brain Room Limited", "organizationalUnitName" => "PHP Documentation Team", "commonName" => "Wez Furlong", "emailAddress" => "wez@example.com" ); // Generate PEM file # Optionally change the passphrase from 'comet' to whatever you want,or leave it empty for no passphrase


这篇关于如何发送XML(登录,命令...)请求并获得响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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