如何使用XML参数编码的XML参数访问API发布方法

时间:2019-03-05 02:34:04

标签: php xml api

我需要使用POST方法访问API,并且该参数需要XML编码的参数, 这就是我所做的:

$url = "http://YourHttp.com/engine/bulk_receiver_api.php"
$post_string = '<?xml version="1.0" encoding="UTF-8"?>
<mt_data>
    <msg_type>txt</msg_type>
    <username>proM_demo</username>
    <password>WU66yxcN3rPV</password>
    <msisdn_sender>ProMDemo</msisdn_sender>
    <msisdn>829283</msisdn>
    <message>hello this is test</message>
    <dr_url>http://www.yoururl.com/yourapplication/dn.php</dr_url> 
</mt_data>';
$header  = "POST HTTP/1.0 \r\n";
$header .= "Content-type: text/xml \r\n";
$header .= "Content-length: ".strlen($post_string)." \r\n";
$header .= "Content-transfer-encoding: text \r\n";
$header .= "Connection: close \r\n\r\n"; 
$header .= $post_string;
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 4);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $header);
$data = curl_exec($ch); 

if(curl_errno($ch)){
    print curl_error($ch);
}else{
    curl_close($ch);
    print curl_error($ch);
}

我需要发送API参数的样子

enter image description here

我仍然遇到问题,没有回复

0 个答案:

没有答案