Simple invocation of API, method of invoking API
Method One: Invoke the API with the front-end method
Full code:
1 <!DOCTYPE HTML>2 3 <HTMLLang= "en">4 <Head>5 <MetaCharSet= "UTF-8">6 <title>Title</title>7 </Head>8 <style>9 Ten </style> One <Body> A <Buttononclick= Request ()>Tijiao</Button> - </Body> - </HTML> the <Script> - functionrequest () { - varXHR= NewXMLHttpRequest; - Xhr.onreadystatechange= function () { + if ( This. ReadyState== 0) { - Console.log ("unsent Open has not yet been called"); + } Else if ( This. ReadyState== 1) { A Console.log ("Opend Open has been called"); at } Else if ( This. ReadyState== 2) { - Console.log ("Receive header Messages"); - } Else if ( This. ReadyState== 3) { - Console.log ("Receive response body"); - } Else { - Console.log (Json.parse ( This. responsetext)); in } - }; to Xhr.open ('GET', "http://route.showapi.com/90-87?showapi_appid=45300&showapi_sign=c28de9d6f79e44369a9abcd40fa3e277"); + xhr.send (); - } the </Script>
If you want to directly use my above code, it is also possible, direct copy is good.
Let me explain the URL above (which is actually the API we call):
Red section: Represents the provider of this API, not the same API, followed by a different number
Green part: Represents the AppID of this API, the application to the API, will have their own AppID
Yellow section: Represents the Appkye of this API, each application of AppID and Appkey application, you can see.
Then I can call it by stitching it together according to the format above.
Method Two: Invoke API with PHP method
The complete code is as follows:
<?PHPHeader("content-type:text/html; Charset=utf-8 ");$fp=fopen("http://route.showapi.com/341-1?showapi_appid=35585&showapi_sign=249e47ff8d5e4bf7b44d55a42e0163ef ","R");Stream_get_meta_data($fp);$result= ""; while(!feof($fp)) {$result.=fgets($fp, 1024);}Echo $result;fclose($fp);
This is the PHP call API method, API splicing and the same as above, the last of the Brown "r" meaning is read-only mode.
Original articles, without permission, please do not reprint!
How to invoke API interface