Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/244.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 通过zend framework 2.3调用web服务时,响应为空_Php_Curl_Zend Framework2 - Fatal编程技术网

Php 通过zend framework 2.3调用web服务时,响应为空

Php 通过zend framework 2.3调用web服务时,响应为空,php,curl,zend-framework2,Php,Curl,Zend Framework2,我是ZendFramework2.3的新手。在我的应用程序中,我需要调用web服务。我使用了类Zend\Http\Client()。。。一切都很好。。。但是回复是空的。。它通过核心php在curl调用中工作 $request = '<?xml version="1.0"?>' . "\n" . '<request><login>email</login><password>password</password></re

我是ZendFramework2.3的新手。在我的应用程序中,我需要调用web服务。我使用了类Zend\Http\Client()。。。一切都很好。。。但是回复是空的。。它通过核心php在curl调用中工作

$request =
'<?xml version="1.0"?>' . "\n" .
'<request><login>email</login><password>password</password></request>';

$client = new Zend\Http\Client();
$adapter = new Zend\Http\Client\Adapter\Curl();
$adapter->setOptions(array(
'curloptions' => array(
    CURLOPT_POST => 1,
    CURLOPT_SSL_VERIFYPEER => false,
    CURLOPT_POSTFIELDS => $request,
    CURLOPT_RETURNTRANSFER => 1
)
));

$client->setUri("https://xyz/getCountries");
$client->setAdapter($adapter);
$client->setMethod('POST');
$response= $client->send();

echo "<pre>\n";
echo htmlspecialchars($response);
echo "</pre>";
$request=
'' . “\n”。
“电子邮件密码”;
$client=new Zend\Http\client();
$adapter=new-Zend\Http\Client\adapter\Curl();
$adapter->setOptions(数组)(
'卷发选项'=>数组(
CURLOPT_POST=>1,
CURLOPT_SSL_VERIFYPEER=>false,
CURLOPT_POSTFIELDS=>$request,
CURLOPT_RETURNTRANSFER=>1
)
));
$client->setUri(“https://xyz/getCountries");
$client->setAdapter($adapter);
$client->setMethod('POST');
$response=$client->send();
回音“\n”;
echo htmlspecialchars($response);
回声“;

您可以通过在
客户端
中而不是在
适配器
中设置
CURLOPT\u POST
CURLOP\u POST字段
选项,直接使用
Http客户端
,如下所示:

echo "<pre>\n";
echo htmlspecialchars($response->getBody());
echo "</pre>";
"; 下面是一个关于如何在Zf2中使用Curl Http适配器的好例子


希望这会有所帮助。

您可以通过在
客户端
而不是
适配器
中设置
CURLOPT_POST
CURLOP_POST字段
选项,直接使用
Http客户端
,如下所示:

echo "<pre>\n";
echo htmlspecialchars($response->getBody());
echo "</pre>";
"; 下面是一个关于如何在Zf2中使用Curl Http适配器的好例子


希望这有帮助。

HTTP客户端请求不返回字符串,而是返回
Zend\HTTP\Response
对象。要查看您可能想要的输出,请执行以下操作:

echo“\n”;
echo htmlspecialchars($response->getBody());
回声“;

另外,我个人会尽量避免直接在适配器上设置选项。这使得在需要时切换适配器更加困难。

HTTP客户端请求不返回字符串,而是返回
Zend\HTTP\Response
对象。要查看您可能想要的输出,请执行以下操作:

echo“\n”;
echo htmlspecialchars($response->getBody());
回声“;
另外,我个人会尽量避免直接在适配器上设置选项。如果需要,则更难切换适配器。

$request=
'' . “\n”。
“电子邮件密码”;
$client=new Zend\Http\client();
$adapter=new-Zend\Http\Client\adapter\Curl();
$adapter->setOptions(数组)(
'卷发选项'=>数组(
CURLOPT_POST=>1,
CURLOPT_SSL_VERIFYPEER=>false,
CURLOPT_POSTFIELDS=>$request,
CURLOPT_RETURNTRANSFER=>1
)
));
$client->setUri(“https://xyz/getCountries");
$client->setAdapter($adapter);
$client->setMethod('POST');
$response=$client->send();
回音“\n”;
echo htmlspecialchars($response->getBody());
回声“;
$request=
'' . “\n”。
“电子邮件密码”;
$client=new Zend\Http\client();
$adapter=new-Zend\Http\Client\adapter\Curl();
$adapter->setOptions(数组)(
'卷发选项'=>数组(
CURLOPT_POST=>1,
CURLOPT_SSL_VERIFYPEER=>false,
CURLOPT_POSTFIELDS=>$request,
CURLOPT_RETURNTRANSFER=>1
)
));
$client->setUri(“https://xyz/getCountries");
$client->setAdapter($adapter);
$client->setMethod('POST');
$response=$client->send();
回音“\n”;
echo htmlspecialchars($response->getBody());
回声“;

您有
$respons=$client->send()。它应该是
$response=$client->send()是的。。。但这是拼写错误您有
$respons=$client->send()。它应该是
$response=$client->send()是的。。。但这是拼写错误你能告诉我哪个版本。。。我正在使用2.2.7版本。。。它不起作用。。。核心php代码运行良好。。。但它不是。。。我试过这个。。。但是它帮不了我…@jaimimmoslake请看我的编辑。你能告诉我哪个版本。。。我正在使用2.2.7版本。。。它不起作用。。。核心php代码运行良好。。。但它不是。。。我试过这个。。。但是它帮不了我…@jaimimmoslake请看我的编辑。
echo "<pre>\n";
echo htmlspecialchars($response->getBody());
echo "</pre>";
$request =
'<?xml version="1.0"?>' . "\n" .
'<request><login>email</login><password>password</password></request>';

$client = new Zend\Http\Client();
$adapter = new Zend\Http\Client\Adapter\Curl();
$adapter->setOptions(array(
'curloptions' => array(
CURLOPT_POST => 1,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_POSTFIELDS => $request,
 CURLOPT_RETURNTRANSFER => 1
)
));

$client->setUri("https://xyz/getCountries");
$client->setAdapter($adapter);
$client->setMethod('POST');
$response= $client->send();

echo "<pre>\n";
echo htmlspecialchars($response->getBody());
echo "</pre>";