Asf_Util::postUrl

To turn this feature on, you need to depend 'CURL'

Read the contents of the URL address through the 'POST' method

Default support for HTTPS address

Default Set: CURLOPT_CONNECTTIMEOUT = 1, CURLOPT_TIMEOUT = 1, CURLOPT_RETURNTRANSFER = 1,
CURLOPT_SSL_VERIFYPEER = 0, CURLOPT_SSL_VERIFYHOST = 0, CURLOPT_FOLLOWLOCATION = 1


Description

public static string Asf_Util::postUrl(string $url [, array $data = array() [, array $opts = array()]])

Parameters

url

URL Address

data

Fill in the associative array

opts

Please refer to curl_setopt_array

Return Values

Return the contents of the request.

call the function 'curl_exec' failure, returns 'Errno' and 'Error' exists in array elements. array('errno' => 'xxx', 'error' => 'yyy')

otherwise return FALSE on failure

Examples

Example #1

Upload POST data; $_POST['user'] = 'zhangsan', $_POST['code'] = 999999

<?php
var_dump(Asf\Util::postUrl("http://www.box3.cn", ['user' => 'zhangsan', 'code' => 999999]));

Example #2

<?php
$ret = Asf\Util::postUrl("http://www.box3.cn", ['user' => 'zhangsan', 'code' => 999999]);
if ($ret && !is_array($ret)) {
    // now it's right
}

Example #3

Set CURL options, CURLOPT_TIMEOUT = 2

<?php
var_dump(Asf\Util::postUrl("http://www.box3.cn", ['user' => 'zhangsan', 'code' => 999999], [CURLOPT_TIMEOUT => 2]));

Example #4

Set CURL options 'CURLOPT_HTTPHEADER'

<?php
var_dump(Asf\Util::postUrl("https://127.0.0.1/index.php?method=Admin.index", NULL,
    [CURLOPT_HTTPHEADER => ['Host: box3.cn']]));

Example #5

Check for error return

<?php
/*
array(2) {
    ["errno"]=>
    int(6)
    ["error"]=>
        string(65) "Could not resolve host: 10111.108.211.223 (Domain name not found)"
}
*/
var_dump(Asf\Util::postUrl("https://10111.108.211.223/index.php?method=Admin.index")),