2016-08-01 5 views
0

이것은 내 PHP 코드입니다.CURL 출력을 얻을 수 없습니다.

<?php 
$xml_post_string = '<?xml version="1.0" encoding="utf-8"?> 
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> 
<soap12:Body> 
<RequestList xmlns="http://tempuri.org/"> 
    <category>syncapppr</category> 
    <subcategory>put_app_presc</subcategory> 
    <paralist>[{"app_List":[{"server_id":"","doctorid":"1266","patientid":"19569","prescriptionid":"870472109","parentid":"","parentserverid":"","FeesDue":"0","clinicid":"1273","caseno":"KAS-5712022016514","casetype":"","reason":"","note":"","diagnosis":"","adate":"22/07/2016","atime":"05:50 AM","fee":"300","refdoctorname":"","canceledbit":"false","rescheduledbit":"false","reschedule_reason":"","recschduledid":"","cancelled_reason":""}],"doc_id":"1266"}]</paralist> 
</RequestList> 
</soap12:Body> 
</soap12:Envelope>'; 

$headers = array(
"Content-type: application/soap+xml; charset=utf-8", 
"Content-length: ".strlen($xml_post_string), 
); 
$ch = curl_init(); 
$fh = fopen('soap_response.xml', 'w'); 

//curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
curl_setopt($ch, CURLOPT_URL, 'http://fakeurl.com/webservices/desktopservices.asmx?op=RequestList'); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
//curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); 
curl_setopt($ch, CURLOPT_TIMEOUT, 100000000); 
//curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); // the SOAP request 
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
//curl_setopt($ch, CURLOPT_HEADER, 1); 
curl_setopt($ch, CURLOPT_FILE, $fh); 
$response = curl_exec($ch); 
//$xml = iconv("GB18030", "utf-8", $response); 
$parser = simplexml_load_string(stripslashes($response)); 
$json = json_encode($parser); 
echo($json); 
curl_close($ch); 
fclose($fh); 
?> 

내 스크립트를 실행할 때 오류가 발생합니다.

경고 :) (simplexml_load_string : 엔티티 : 라인 1 : 파서 ​​오류 : 태그 예상 시작 '<'C에서 발견되지 \ XAMPP \ htdocs를 \ DsAdmin \ call_1.php 라인 41

경고 : simplexml_load_string() : 1의 C : \ XAMPP \ htdocs를 \ DsAdmin \ call_1.php 라인 41

경고^C에서 :) (simplexml_load_string \ XAMPP \ htdocs를 \ DsAdmin \ call_1.php 라인 41에

하지만 내가 볼 수 있듯이 파일 출력은 CURL 출력입니다. 영형. 그 파일에서 나는 정확한 출력을 얻고있다. 내 코드에서 무엇이 잘못되었는지 이해할 수 없다.

나는 그물에 많은 해결책을 심의했으나 아무런 효과가 없었으므로, 어떤 사람이 나를 도와 줄 수 있습니까?

파일 출력

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><RequestListResponse xmlns="http://tempuri.org/"><RequestListResult><syncapp_pres_list><SyncApp_Pres_Master><app_List><Appointment_Master><id>0</id><server_id>15238</server_id></Appointment_Master></app_List><startfrom>0</startfrom><endfrom>0</endfrom><clinicid>0</clinicid></SyncApp_Pres_Master></syncapp_pres_list></RequestListResult></RequestListResponse></soap:Body></soap:Envelope>

+0

XML 한 줄로 시도 했습니까? – tanaydin

+0

@tanaydin 님이 질문을받지 못했습니다. – Archish

+0

$ xml_post_string에 문제가 생길 수있는 몇 줄의 새로운 줄이 있습니다. – tanaydin

답변

0
$xml_post_string = '<?xml version="1.0" encoding="utf-8"?> 

당신이 닫는? php에 태그를이 줄. 는 XML 완전히 손상된 것, 응답에 ... 그것을 좋아

$xml_post_string = '<?xml version="1.0" encoding="utf-8" 
실행하지 않는
+0

아니요 PHP 태그를 닫고 있지 않습니다. 전체 문자열은 작은 따옴표 ('') 사이에 있습니다. 그리고 나는 파일에서 currect 출력을 얻고있다. – Archish

+0

당신은 항상 그것을 \\ \>로 탈출하여 확신 할 수있다. – Kalko

+0

@Kalko 당신이 제안한대로 해봤지만 도움이되지 않았습니다. ( – Archish

0

stripslashes을합니다. rawurlencode$xml_post_stringCURLOPT_POSTFIELDS입니다.

+0

did not work :(. – Archish

0

나는 당신의 코드를 시도했지만 아무 소용이 없다. 당신이 제공 한 fakeurl은 작동하지 않습니다 (선장님 께 감사드립니다). 그리고 그 결과물을 가지고 있지 않으면 문제가 무엇인지 말할 수 없습니다. 문제는 cURL이지만 코드 대신 TRUE를 반환 할 것입니다. (처음에 질문 한 내용입니다)

한 번 cURL 응답을받지 못하고 CURLOPT_FOLLOWLOCATION을 TRUE로 설정하여 문제를 해결했습니다. 이를 사용하지 않으면 리디렉션 된 페이지 내용 대신에 리디렉션에 NULL을 반환합니다.

cURL의 작동 URL을 알려 주시면 문제를 자세히 볼 수있어서 기쁩니다.

관련 문제