我有一个具有以下功能的课程。当我直接调用该函数时,它可以工作,但是如果我在循环内调用该函数,则会出现错误:Cannot connect to host
. 有人可以帮助我吗?:) 提前致谢。
public function exportProfile($xml) {
$_myRequest = curl_init("https://www.example.com/postProfile");
curl_setopt($_myRequest, CURLOPT_POST, 1);
curl_setopt($_myRequest, CURLOPT_USERPWD, "testUser:testPassword");
curl_setopt($_myRequest, CURLOPT_HTTPHEADER, Array("Content-Type: application/xml"));
curl_setopt($_myRequest, CURLOPT_POSTFIELDS,$xml );
curl_setopt($_myRequest, CURLOPT_RETURNTRANSFER, 1);
// do request, the response text is available in $_response
$_response = curl_exec($_myRequest);
$err = curl_error($_myRequest) ;
echo $err;
$_statusCode = curl_getinfo($_myRequest, CURLINFO_HTTP_CODE);
// close cURL resource, and free up system resources
curl_close($_myRequest);
return simplexml_load_string($_response);
}