2016-09-14 2 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

나는 이것을 위해 cURL을 사용할 것을 권장합니다. 다음 예제는 수행하려는 작업을 수행해야합니다.

$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);