我正在尝试使用 Yii HTTP 客户端(正在开发中)重写以下 HTTP 请求,文档中使用 ZEND Http 客户端举例说明:
// Create Http client to send the paymentRequest
// We use Zend_Http_Client here, feel free to use your favourite HTTP client library
$client = new Zend_Http_Client($this->donationRequest->getSipsUri());
$client->setParameterPost('Data', $this->donationRequest->toParameterString());
$client->setParameterPost('InterfaceVersion', 'HP_2.3');
$client->setParameterPost('Seal', $this->donationRequest->getShaSign());
$response = $client->request(Zend_Http_Client::POST);
使用 Yii,这就是我的想法:
$client = new Client();
$data = [
'Data' => $this->donationRequest->toParameterString(),
'InterfaceVersion' => 'HP_2.3',
'Seal' => $this->donationRequest->getShaSign()
];
$client->createRequest()
->setMethod('post')
->setUrl($this->donationRequest->getSipsUri())
->setData($data)->send();
启动此代码时,出现以下错误:
fopen(): php_network_getaddresses: getaddrinfo failed: No address associated with hostname
如何正确调试问题(即查看提交的内容并使用结果通过浏览器解决方案进行测试)?
使用 Yii 替代方案生成与 Zend 示例类似的请求的任何建议
最佳答案
我用过Guzzle相反,它与 Yii2 配合得很好,并且界面足够简单。谢谢
关于PHP Yii2 HTTP 客户端调试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32924879/