-
-
Save crazytonyi/10222135ab7b4d9407d2103130a94cfa to your computer and use it in GitHub Desktop.
<?php | |
$client = new \GuzzleHttp\Client(); | |
$headers = ['x-api-key' => 'MY API KEY']; | |
$options = [ | |
'headers' => ['x-api-key' => 'MY API KEY'], | |
'debug' => true, | |
]; | |
try { | |
$resp = $client->request('GET', 'https://beta.check-mot.service.gov.uk',$options); | |
} catch (\GuzzleHttp\Exception\ClientException $e) { | |
$resp = $e->getResponse(); | |
} | |
echo $resp->getBody(); |
This is the output
The output from what? That looks like it's all command line curl, is that right? If so, it seems like you get a 403 response no matter what. In which case it's not an issue with the code, right?
Thats from command line yes. If I use curl -H "Accept: application/json" -H "x-api-key: your_api_key " \https://beta.check-mot.service.gov.uk/trade/vehicles/mot-tests\?registration=XX10ABC, I get a output and works with any car reg
Does that also work if you update the URL for the guzzle request?
Would I need to update the actual url within controller?
The URL in the request.
By using function?
public function apitest(){
$client = new \GuzzleHttp\Client();
$headers = ['x-api-key' => 'Key here'];
$options = [
'headers' => ['x-api-key' => 'Key here'],
'debug' => true,
];
try {
$resp = $client->request('GET', 'https://beta.check-mot.service.gov.uk/trade/vehicles/mot-tests\?registration=XX10ABC
',$options);
} catch (\GuzzleHttp\Exception\ClientException $e) {
$resp = $e->getResponse();
}
echo $resp->getBody();
}
< HTTP/1.1 200 Connection established
<
< HTTP/1.1 403 Forbidden
< Content-Type: application/json
< Content-Length: 43
< Connection: keep-alive
< Date: Thu, 19 Apr 2018 02:23:32 GMT
< x-amzn-RequestId: a7b95f2a-4378-11e8-823e-1707b1755be6
< x-amzn-ErrorType: MissingAuthenticationTokenException
< x-amz-apigw-id: FkSRrEcqjoEFtEA=
< X-Cache: Error from cloudfront
< Via: 1.1 db29ce630f36ae7f48a6957d9d80d0be.cloudfront.net (CloudFront)
< X-Amz-Cf-Id: on1G43o2CYZFH2yRcsUP3oHYZQQhWgw76nPyf8Y2vV_zJOy1yeqh2g==
< Set-Cookie: visid_incap_1151098=X2wckoG7QmybXDPqnkMqq6P911oAAAAAQUIPAAAAAADGm6ee6C6EhpemMK9YwpYd; expires=Thu, 18 Apr 2019 12:14:28 GMT; path=/; Domain=.check-mot.service.gov.uk
< Set-Cookie: nlbi_1151098=OTNSeizpYUF7Qr0BR22hbQAAAABu3Md5TDawJ/lVqbRs89aW; path=/; Domain=.check-mot.service.gov.uk
< Set-Cookie: incap_ses_374_1151098=snDnCPTc/UoDDCP/N7cwBaP911oAAAAA/MtqNe7LCKrwvTTtEI8f3A==; path=/; Domain=.check-mot.service.gov.uk
< Set-Cookie: ___utmvmSNukcFcB=AAgXhOmvhYx; path=/; Max-Age=900
< Set-Cookie: ___utmvaSNukcFcB=XvV�lOYx; path=/; Max-Age=900
< Set-Cookie: ___utmvbSNukcFcB=oZn
< XjyOUalR: itK; path=/; Max-Age=900
< X-Iinfo: 6-48709975-48709978 NNNN CT(1 6 0) RT(1524104611734 108) q(0 0 0 0) r(0 0) U5
< X-CDN: Incapsula
<
{"message":"Missing Authentication Token"}