2016-08-01 14 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:Cで1:\ XAMPP \ htdocsに\ DsAdmin \ call_1.phpライン上の41

警告:simplexml_load_string():^ Cで:\ XAMPP \ htdocsに\ DsAdmin \ call_1.phpライン41

私はCURLの出力をファイルに保存していますo。そのファイルには正しい出力が得られています。私は自分のコードで何が間違っているのか理解できません。

私はネット上で多くのソリューションを審査していましたが、何も働かなかったので、ここで私を助けることができますか?あなたが閉じている?phpのタグをこの行に

ファイル出力

<?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

1行のXMLで試しましたか? – tanaydin

+0

@tanaydinはあなたの質問をしなかった。 – Archish

+0

$ xml_post_stringに新しい行がいくつかありますが、それが問題の原因になっている可能性があります。 – tanaydin

答えて

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

。それのような...

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

私はphpタグを閉じていません。その文字列全体は一重引用符( '')の間にあります。そして私はファイルにcurrectの出力を得ています – Archish

+0

あなたはいつも確実に\\ \>にエスケープすることができます。 – Kalko

+0

@Kalko私はあなたが示唆したようにしましたが、それは私を助けませんでした:( – Archish

0

が応答にstripslashesを実行していない、それは完全に壊れれるXML作ります。 rawurlencode$xml_post_stringCURLOPT_POSTFIELDSです。

+0

did not work :(。 – Archish

0

私はあなたのコードを試しましたが、役に立たなかった。あなたが提供したfakeurlは動作しません(キャプテンに感謝します)、それから出力を出さずに問題が何であるかは分かりません。問題はcURLですが、おそらくコードの代わりにTRUEを返すでしょう(しかし、それは最初に尋ねたものです)

私はかつてcURLレスポンスを得られず、CURLOPT_FOLLOWLOCATIONをTRUEに設定して問題を修正しました。それがなければ、リダイレクトされたページの内容ではなく、リダイレクト時にNULLを返します。

cURLの動作URLを私に提供すると、この問題をさらに詳しく調べることができてうれしいです。

関連する問題