Используйте Guzzle с API name.comPhp

Кемеровские программисты php общаются здесь
Гость
Используйте Guzzle с API name.com

Сообщение Гость »


use Guzzle wit name.com api

that is the Curl example

Код: Выделить всё

curl -u 'username:token' 'https://api.dev.name.com/v4/domains:checkAvailability' -X POST -H 'Content-Type: application/json' --data '{"domainNames":["example.org"]}' 
php curl with Guzzle to do the previous request

Код: Выделить всё

$username=''; $token=''; $client = new GuzzleHttp\Client(); $url = $endpoint.'/v4/domains:checkAvailability'; $headers = ['Authorization' => "$username:$token",'Content-Type' => 'application/json']; $data ='{"domainNames":["example.com"]}'; $data=json_decode($data,true); $res = $client->post($url,['headers' => $headers ,'form_params' => $data  ]); 
Questions :

1-Authorization is missing some thing like basic

2-name.com required --data as string but Guzzle required it as array

correct way to pass the data

thanks


Источник: https://stackoverflow.com/questions/781 ... me-com-api

Вернуться в «Php»