API Interface Code

Source: Internet
Author: User

Interface design documentation and code focus on two, one is authentication, one is the escalation data, that is, the post data to the API interface.

The authentication section requires you to get tokens (tokens) based on the URL address provided in the document, the username and password of the Access interface.

A more complex token design may require a digital signature technique, which can be referenced in the following links: Digital verification
The code will need to use the HttpClient class library.

Public Function Getoken () {
Include ("HttpClient.class.php");

Address of destination Host
$Client = new HttpClient ("IP");
Requested page address
$url = "Your url";
The parameters of the post
$params = Array (' account ' = ' accounts ', ' password ' = ' password ');
$content = $Client->quickpost ($url, $params);
if (! $content) {
Print_r (0);
}
Return Json_decode ($content, true);
}

Then submit the data:

Public Function Upload_data ($token, $params) {
Requested page address
$url = "Your url?token=". $token;
$ch = Curl_init ();
curl_setopt ($ch, Curlopt_url, $url);
curl_setopt ($ch, Curlopt_post, 1);
curl_setopt ($ch, Curlopt_header, 0);
curl_setopt ($ch, Curlopt_returntransfer, 1);
curl_setopt ($ch, Curlopt_postfields, $params);
$result = curl_exec ($ch);
Curl_close ($ch);
Return Json_decode ($result, true);
}

The submission of the data is successful.

API Interface Code

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.