发送HTTP请求
通过http post发送json数据
PHP扩展CURL的用法详解
PHP中使用cURL实现Get和Post请求的方法
php发送http请求
PHP curl CURLOPT_RETURNTRANSFER参数的作用使用实例
PHP中CURL方法curl_setopt()函数的参数
PHP中发送HTTP请求可以使用curl
或者file_get_contents()
方法,curl
使用前需要在php.ini
中将extension=php_curl.dll
前面的分号去掉
1 |
|
通过命令行运行命令php filename.php
即可
响应的服务端为Python的Flask实现1
2
3
4
5
6
7
8
9
10
11
12
13
14
15from flask import Flask, request, jsonify
app = Flask(__name__)
@app.route('/')
def index():
return 'Hello World!'
@app.route('/hello', methods=['POST'])
def hello():
name = request.json['name'] if request.json['name'] else ''
return jsonify({'message': 'Hello '+name})
if __name__ == '__main__':
app.run(host='0.0.0.0',debug=True)
去除Object中的部分属性
使用unset()
方法即可去除指定Ojbect中的指定属性1
2
3
4
5
6
7$a = new stdClass();
$a->new_property = 'foo';
var_export($a); // -> stdClass::__set_state(array('new_property' => 'foo'))
unset($a->new_property);
var_export($a); // -> stdClass::__set_state(array())
闭包
闭包即为匿名函数。创建一个没有名称的函数,使用use
关键字来连接闭包与外界的变量,使子函数可以使用父函数的局部变量1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20$num = 1;
function test1($num) {
$result = 1;
$a = function() use ($num, &$result){
$result += $num;
print("result in a: ".$result."\n");
};
$a();
print($result);
print("\n");
//不加&则不会影响父函数的局部变量
$b = function() use ($num, $result) {
$result -= $num;
print("result in b: ".$result."\n");
};
$b();
print($result);
}
test1($num);