I tried to get data from outside webservice.
I got API url like http://wsq.check.com:50001/Services/appsspg.asmx/GetActionLog
and the data for the function is $data = array("parameter1" => "1");
. So, how could i get the data from that external webservice?
1 Answer
To access external webservice, you can use Zend HTTP Client
class, using the below code:
protected $_httpClientFactory;
public function __construct(
\Magento\Framework\HTTP\ZendClientFactory $httpClientFactory
) {
$this->_httpClientFactory = $httpClientFactory;
}
/**
* Function to create CURL Request to External Server
*/
public function connect()
{
$data['parameter1'] = 1;
$client = $this->_httpClientFactory->create();
$client->setUri($url);
$client->getUri()->setPort($port);
$client->setConfig(['timeout' => 300]);
$client->setHeaders(['Content-Type: application/json', 'Accept: application/json']);
$client->setMethod(\Zend_Http_Client::POST);
$client->setRawData(json_encode($data));
try {
$responseBody = $client->request()->getBody();
echo '<pre>';
print_r($responseBody);
die;
} catch (\Exception $e) {
echo $e->getMessage();
}
}
}
-
so, where did i place the url wsq.check.com:50001/Services/appsspg.asmx/GetActionLog ? Oct 3, 2017 at 7:46
-
ah sry, i dont see the $url part. But where could i find the port? Oct 3, 2017 at 7:50
-
-
should the url be "wsq.check.com:50001/Services/appsspg.asmx?wsdl" or "wsq.check.com:50001/Services/appsspg.asmx/GetActionLog" ? Oct 3, 2017 at 8:49
-