[英]How to assign result fro curl to a variable?
我需要做一個簡單的POST
請求並解析結果。 為此,我在php
使用curl
。 問題是我無法將結果分配給變量-它只會打印。
我的方法:
private function sendRequest($data)
{
$ch = curl_init(self::IP . ':' . self::PORT);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($ch); // HERE IT PRINTS
curl_close($ch);
$parsed_result = @simplexml_load_string(trim($result)); // OR HERE IT
die(var_dump(isset($parsed_result->request_error)));
if (isset($parsed_result->request_error))
$this->AJAXResult(TRUE, (string) $parsed_result->request_error->text);
}
如果要使curl_exec返回發布請求的結果,則必須添加: curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1)
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.