我正試圖通過curl
與兩個zf2
應用程序建立通信。所需響應在xml
中。到目前爲止,我可以建立連接,並返回xml
作爲響應。在ZF2中實現捲曲
問題
的問題是,我不能在我的xml response
。每當我遍歷和的var_dump我$response->getContent
的視圖源代碼,我得到儘可能
string(142) "<?xml version="1.0" encoding="UTF-8"?>
<myxml>
<login>
<status>success</status>
<Err>None</Err>
</login>
</myxml>
"
,當我只需var_dump
我的$response
,我得到一個object(Zend\Http\Response)#440
。
simplexml_load_string($response->getContent())
給了我一個空白頁。
另外print $data->asXML()
給我Call to a member function asXML() on a non-object
錯誤。我在這裏做錯了什麼?
捲曲請求動作
$request = new \Zend\Http\Request();
$request->getHeaders()->addHeaders([
'Content-Type' => 'application/x-www-form-urlencoded; charset=UTF-8'
]);
$request->setUri('http://localhost/app1/myaction');
$request->setMethod('POST'); //uncomment this if the POST is used
$request->getPost()->set('curl', 'true');
$request->getPost()->set('email', '[email protected]');
$request->getPost()->set('password', '2014');
$client = new Client;
$client->setAdapter("Zend\Http\Client\Adapter\Curl");
$response = $client->dispatch($request);
var_dump($response);//exit;
//$response = simplexml_load_string($response->getContent());
//echo $response;exit;
return $response;
捲曲響應行動
$php_array=array(
'login'=>array(
'status'=>'failed','Err'=>'Unauthorised Access'
)
);
$Array2XML=new \xmlconverter\Arraytoxml;
$xml = $Array2XML->createXML('myxml', $php_array);
$xml = $xml->saveXML();
//echo $xml;exit;
$response = new \Zend\Http\Response();
$response->getHeaders()->addHeaderLine('Content-Type', 'text/xml; charset=utf-8');
$response->setContent($xml);
return $response;
的Array2XML
可以發現here
任何想法?
simplexml_load_string返回一個對象SimpleXMLElement – Hooli
如果你得到一個空白頁面,你有關閉顯示錯誤(這是ZF默認值)。檢查Web服務器錯誤日誌以查看實際錯誤。 –
您是否嘗試過使用原始CURL而不是zf2適配器? – Conti