2016-09-14 4 views
0

XMLオブジェクトを含むPOSTリクエストをサーバーに送信するPHPコードがありますが、それは機能しません。リクエストに問題があると思います。私は彼らが提案したことをやろうとしましたが、それでも動作しません。 ここに私のPHPコードはあります:PHPでXMLオブジェクトリクエストを送信する

$url = 'http://example/service.asmx'; 
$xml='<?xml version="1.0" encoding="utf-8"?> 
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soap:Body> 
<Get_schadual xmlns="http://tempuri.org/"> 
<User>exmaple</User> 
</Get_schadual> 
</soap:Body> 
</soap:Envelope>'; 
$post_data = array('xml' => $xml); 
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n X-Requested-With: XmlHttpRequest", 
'method' => 'POST', 
'content' => http_build_query($post_data))); 
$context = stream_context_create($options); 
$result = file_get_contents($url, false, $context); 
var_dump($result); 
+0

「動作しません」という意味を指定してください。あなたはどんなエラーを受け取っていますか? –

答えて

0

私はあなたのためにそれを使用することをお勧めします。次の例では、実行しようとしていることを達成する必要があります。

$xml = "<?xml version="1.0" encoding="utf-8"?> 
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soap:Body> 
<Get_schadual xmlns="http://tempuri.org/"> 
<User>exmaple</User> 
</Get_schadual> 
</soap:Body> 
</soap:Envelope>"; 

$ch = curl_init(); 

curl_setopt($ch, CURLOPT_URL, "http://example/service.asmx"); 
curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml')); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); 

$result = curl_exec($ch); 
curl_close($ch); 

var_dump($result); 
関連する問題