PHP get传值和post传值(不用表单形式)

GET传值

$html = file_get_contents("URL?a=xxx&b=xxx");
dump($html);

函数file_get_contents():

file_get_contents

Reads entire file into a string

<?php
function file_get_contents(
    string $filename,
    bool $use_include_path = false,
    $context,
    int $offset = 0,
    ?int $length
): string|false { }
@param string $filename — Name of the file to read.

@param bool $use_include_path
[optional]

Note: As of PHP 5 the FILE_USE_INCLUDE_PATH constant can be used to trigger include path search.

@param resource $context
[optional]

A valid context resource created with stream_context_create. If you don't need to use a custom context, you can skip this parameter by null.

@param int $offset[optional]

The offset where the reading starts.

@param int|null $length
[optional]

Maximum length of data read. The default is to read un

POST传值

$arr = ['key1'	=>	value1,
		'key2'	=>	value2,
		...
		];
$html = send_post('URL',$arr);
dump($html);

函数send_post():

/**
 * 发送post请求
 * @param string $url 请求地址
 * @param array $post_data post键值对数据
 * @return string
 */
function send_post($url, $post_data) {
    $postData = http_build_query($post_data);
    $options = array(
        'http' => array(
            'method' => 'POST',
            'header' => 'Content-type:application/x-www-form-urlencoded',
            'content' => $postData,
            'timeout' => 15 * 60 // 超时时间(单位:s)
        )
    );
    $context = stream_context_create($options);
    $result = file_get_contents($url, false, $context);

    return $result;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值