如何使用控制器从 laravel 中的 enom api 获取数据
how to get the data from enom api in laravel using controller
通过这个 link
如何使用控制器在 laravel 中获取以下数据。
<interface-response>
<DomainName>enom.com</DomainName>
<RRPCode>211</RRPCode>
<RRPText>Domain not available</RRPText>
<Command>CHECK</Command>
<APIType>API.NET</APIType>
<Language>eng</Language>
<ErrCount>0</ErrCount>
<ResponseCount>0</ResponseCount>
<MinPeriod>1</MinPeriod>
<MaxPeriod>10</MaxPeriod>
<Server>sjl1vwresell_t</Server>
<Site>eNom</Site>
<IsLockable>True</IsLockable>
<IsRealTimeTLD>True</IsRealTimeTLD>
<TimeDifference>+8.00</TimeDifference>
<ExecTime>0.328</ExecTime>
<Done>true</Done>
<TrackingKey>1f5b6d77-f715-42af-94a2-a30e0a40f847</TrackingKey>
<RequestDateTime>5/2/2018 12:58:22 AM</RequestDateTime>
<debug/>
</interface-response>
如何将 url 传递给控制器并在视图中显示数据。
您可以使用这个库:
https://github.com/ixudra/curl
在你的控制器中:
use Ixudra\Curl\Facades\Curl;
public function test()
{
$response = Curl::to('https://resellertest.enom.com/interface.asp?command=check&sld=enom&tld=com&responsetype=xml&uid=resellid&pw=resellpw')
->get();
//dd($response); //check if we are getting a response
return view('index', array(
'response' => $response,
));
}
数据转储 dd($response);
将如下所示:
回答与评论不同的问题:
1st 你的表单应该路由到控制器中的方法,并且表单(POST 方法)输入应该有:
<input type="text" name="sld">
<input type="text" name="tld">
...
<input type="hidden" name="_token" value"{{ csrf_token() }}">
2nd 将表单请求捕获到控制器中的方法:
use Illuminate\Http\Request;
public function test(Request $request)
{
$sld = $request['sld'];
$tld = $request['tld'];
//if you want, initialize more variables here...
$response = Curl::to('https://resellertest.enom.com/interface.asp?command=check&sld='. $sld .'&tld='.
$tld .'&responsetype=xml&uid=resellid&pw=resellpw')
->get();
//dd($response); //check if we are getting a response
return view('index', array(
'response' => $response,
));
}
通过这个 link
如何使用控制器在 laravel 中获取以下数据。
<interface-response>
<DomainName>enom.com</DomainName>
<RRPCode>211</RRPCode>
<RRPText>Domain not available</RRPText>
<Command>CHECK</Command>
<APIType>API.NET</APIType>
<Language>eng</Language>
<ErrCount>0</ErrCount>
<ResponseCount>0</ResponseCount>
<MinPeriod>1</MinPeriod>
<MaxPeriod>10</MaxPeriod>
<Server>sjl1vwresell_t</Server>
<Site>eNom</Site>
<IsLockable>True</IsLockable>
<IsRealTimeTLD>True</IsRealTimeTLD>
<TimeDifference>+8.00</TimeDifference>
<ExecTime>0.328</ExecTime>
<Done>true</Done>
<TrackingKey>1f5b6d77-f715-42af-94a2-a30e0a40f847</TrackingKey>
<RequestDateTime>5/2/2018 12:58:22 AM</RequestDateTime>
<debug/>
</interface-response>
如何将 url 传递给控制器并在视图中显示数据。
您可以使用这个库: https://github.com/ixudra/curl
在你的控制器中:
use Ixudra\Curl\Facades\Curl;
public function test()
{
$response = Curl::to('https://resellertest.enom.com/interface.asp?command=check&sld=enom&tld=com&responsetype=xml&uid=resellid&pw=resellpw')
->get();
//dd($response); //check if we are getting a response
return view('index', array(
'response' => $response,
));
}
数据转储 dd($response);
将如下所示:
回答与评论不同的问题:
1st 你的表单应该路由到控制器中的方法,并且表单(POST 方法)输入应该有:
<input type="text" name="sld">
<input type="text" name="tld">
...
<input type="hidden" name="_token" value"{{ csrf_token() }}">
2nd 将表单请求捕获到控制器中的方法:
use Illuminate\Http\Request;
public function test(Request $request)
{
$sld = $request['sld'];
$tld = $request['tld'];
//if you want, initialize more variables here...
$response = Curl::to('https://resellertest.enom.com/interface.asp?command=check&sld='. $sld .'&tld='.
$tld .'&responsetype=xml&uid=resellid&pw=resellpw')
->get();
//dd($response); //check if we are getting a response
return view('index', array(
'response' => $response,
));
}