file_get_contents url请求/传输数据

/**
 * 用file_get_contents函数,以post方式发送数据处理
 */
function httpPostJson($url, $data = ''){
    $opts = array(
        'http' => array(
            'method'  => 'POST',
            'header'  => "Content-type: application/json;charset=UTF-8;Content-Length: " . strlen($data),
            'timeout' => 30,
            'content' => $data,
        ),
    );
    //文本数据流创建
    $context = stream_context_create($opts);
    return file_get_contents($url, FALSE, $context);
}

猜你喜欢

转载自blog.csdn.net/qq_35979073/article/details/80270036