如何使用控制器从laravel中获取enom api中的数据

时间:2018-05-02 08:04:17

标签: laravel laravel-5 laravel-4 laravel-5.2

通过此链接

  

https://resellertest.enom.com/interface.asp?command=check&sld=enom&tld=com&responsetype=xml&uid=resellid&pw=resellpw

如何使用控制器在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传递给控制器​​并在视图中显示数据。

1 个答案:

答案 0 :(得分:1)

您可以使用此库: 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);将如下所示:

enter image description here

从评论中回答其他问题:

第一您的表单应该路由到控制器中的方法,并且表单(POST方法)输入应该有:

<input type="text" name="sld">
<input type="text" name="tld">
...
<input type="hidden" name="_token" value"{{ csrf_token() }}">

第二将表单请求捕获到控制器中的方法:

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,
        ));
    }