开发者

How can I do this in PHP / http post?

I have been given API documentation which I don't quite get as there is no URL to connect up to?

http://support.planetdomain.com/index.php?_m=downloads&_a=viewdownload&downloaditemid=14&nav=0

I'd prefer doing this in PHP..

How can I run a 10 it开发者_开发百科eration loop, doing a check if domain is available, if it's response is available, then perform the register command and exit the script (using the code provided in thd documentation).

Thank you.


For the basics, I suggest using cURL to access resources by HTTP POST.

I put this into a function:

function api_call($url,$data,$timeout=20)
  {
  $response=false;

  $ch=curl_init($url);
  curl_setopt_array($ch,array(CURLOPT_RETURNTRANSFER=>true,CURLOPT_NOBODY=>false,CURLOPT_TIMEOUT=>$timeout,CURLOPT_FORBID_REUSE=>1,CURLOPT_FRESH_CONNECT=>1,CURLOPT_POST=>true));


  curl_setopt($ch, CURLOPT_POSTFIELDS, $data);//this is an array containing the data you're sending them - an associative array describing which call.

  //data example:
  //array('operation'=>'user.verify','admin.username'=>'you','admin.password'=>'pass','reseller.id'=>'xxx') 

  $response=curl_exec($ch);

  $status_code=intval(curl_getinfo($ch,CURLINFO_HTTP_CODE));
  curl_close($ch);

  return array('status'=>$status_code,'url'=>$url,'data'=>$response);
  }

However, you need to supply a URL. Lucanos noted in the comments it is "api.planetdomain.com/servlet/TLDServlet".

http://support.planetdomain.com/index.php?_m=knowledgebase&_a=viewarticle&kbarticleid=77

by the way, I only use cURL for GET requests, so I might be missing some details on how to do a POST right. I tried to fill it in, though.

You ask "How can I run a 10 iteration loop, doing a check if domain is available, if it's response is available, then perform the register command and exit the script (using the code provided in thd documentation)."

Well, here's some pseudocode mixed with valid PHP. I don't know the domainplanet API as you know, so this will NOT work as is but it should give you a decent idea about it.

 for($i=0;$i<10;$i++)
    {
    //set up the domain check call
    $domains=array('futunarifountain.co.uk','megahelicopterunicornassaultlovepageant.ly');
    $domain_check_call=array('domain.name'=>$domains[$i]);
    $domain_info=api_call($dp_base_url,$domain_check_call);

    $info=json_decode($domain_info,true);//IF they use JSON and not XML or something

    if($info['domain']['status']=='available')
        {
        $register_call=something();//make the API calls to register the domain, similar to the above
        if($register_call['success']){ exit();/*or whatever*/ }
        }

    }

Hope that helps get you on the right track.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜