Firework 框架依赖项

v1.3.0 2021-02-13 12:41 UTC

This package is auto-updated.

Last update: 2024-09-15 00:02:51 UTC


README

基本用法

<?php

use Http\Http; // Import main class
require __DIR__ . 'path-to-autoload'; // Import composer autoload 

$http = new Http; // Create new Http class
$http->setUrl("https://httpbin.org/post"); // Add HTTP url

// Print headers of the request
print_r(
    $http->getHeaders()
);

// Print body of the request
print_r(
    $http->getBody() 
);

// Print response of the post request
print_r(
    $http->post(
        [
            "name" => "jonn",
            "age" => 25
        ]
    )
);

文档

setUrl()

设置请求的 URL
参数
$url = 请求的 URL

"http://example.com/"

 

$http->setUrl($url);

setHeaders()

设置请求的头部信息
参数
$headers = 字符串或头部信息数组

["HeaderName:HeaderValue", "HeaderName2:HeaderValue2"] or "HeaderName:HeaderValue"

 

$http->setHeaders($headers);

setCurlSettings()

设置请求的 cURL 配置
参数
$arr = 配置数组

[CURLOPT_URL => "http://example.com", CURLOPT_HEADER => false]

 

$http->setCurlSettings($arr);

removeCurlSettings()

移除请求的 cURL 配置
参数
$settings = 配置字符串数组

[CURLOPT_POST, CURLOPT_HEADER] or CURLOPT_POST

 

$http->removeCurlSettings($settings);

getHeaders()

返回请求的头部信息

$http->getHeaders(); 

getBody()

返回请求的响应体

$http->getbody();

get()

向 URL 发送 GET 请求
参数
$arr = 请求值数组

["name" => "john", "age" => 25]

 

$http->get($arr);

post()

向 URL 发送 POST 请求
参数
$arr = 请求值数组

["name" => "john", "age" => 25]

 

$http->post($arr);

put()

向 URL 发送 PUT 请求
参数
$arr = 请求值数组

["name" => "john", "age" => 25]

 

$http->put($arr);

delete()

向 URL 发送 DELETE 请求
参数
$arr = 请求值数组

["name" => "john", "age" => 25]

 

$http->delete($arr);

patch()

向 URL 发送 PATCH 请求
参数
$arr = 请求值数组

["name" => "john", "age" => 25]

 

$http->patch($arr);

isOk()

返回布尔值

$http->isOk();

getResponseCode()

返回响应代码字符串

$http->getResponceCode();