How to invoke API interface

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.