Aetherdan Posted May 7, 2018 Posted May 7, 2018 // Create a URL object $url = \IPS\Http\Url::external( $API_URL ); // Now fetch it try { $response = $url->request()->get(); } catch( \IPS\Http\Request\Exception $e ) { return FALSE; } catch( \RuntimeException $e ) { return FALSE; } if ($response->httpResponseCode == 200) { return TRUE; } else { return FALSE: } Is this the correct way to validate that a url request is successful?
bfarber Posted May 7, 2018 Posted May 7, 2018 Yes, assuming that you consider a response code other than 200 to be unsuccessful (many APIs, for instance, may return response codes other than 200 validly).
Recommended Posts
Archived
This topic is now archived and is closed to further replies.