このトピックでは、HTTP関数の構文、説明、パラメーター、および戻り値について説明します。 このトピックでは、これらの関数の例も示します。

http_request

この関数の詳細を次の表に示します。
項目 説明
構文 http_request(req_info)
機能 非ブロッキングモードでHTTPリクエストを実行します。
パラメーター
req_info: リクエスト設定。 データ型: dictionary。 このパラメータには、次のフィールドが含まれます。
  • addr: リクエストのURL。 このフィールドは必須です。
  • method: リクエストメソッド。 デフォルトでは、GETメソッドが使用されます。 このフィールドはオプションです。
  • retry: the number of retries. デフォルト値:1。 最大値: 5。 このフィールドはオプションです。
  • timeout: タイムアウト期間。 デフォルト値: 1000 最大値: 10000。 単位:ms。 このフィールドはオプションです。
  • send_headers: リクエストヘッダー。 データ型: dictionary。 The key of the field indicates the request header, and the value of the field indicates the content of the request header. このフィールドはオプションです。
  • body: リクエストボディ。 リクエストボディのサイズは65,535バイトを超えることはできません。 このフィールドはオプションです。
戻り値
  • 関数が実行された場合、ディクショナリ型の次のキーと値のペアを返します。
    • code: HTTPステータスコード。
    • status: 応答ステータス。
    • headers: ディクショナリ型のレスポンスヘッダー。 この値は小文字です。
    • body: レスポンスボディ。
  • 関数の実行に失敗した場合、falseの値を返します。
req_info = []
set(req_info, 'addr', 'http:// 127.0.0.1:7088/test_http?ua=iphone')
set(req_info, 'retry', 1)
set(req_info、'timeout' 、1000)
set(req_info、'method' 、'GET')
set(req_info、'body' 、'ABC ')
req_hdr = []
set(req_hdr, 'Content-Type', 'application/json; charset=utf-8 ')
set(req_hdr、'Connection' 、'close')
set(req_info, 'send_header', req_hdr)
rs = http_request(req_info)
if rs {
    say(concat('code: ', get(rs, 'code')))
    say(concat('status: ', get(rs, 'status')))
    headers = get(rs, 'header')
    age = ''
    age = get (ヘッダー、'age')
    speed = ''
    speed = get (ヘッダー、'speed')
    say(concat('age: ', age, ' speed: ', speed))
    say(concat('body: ', get(rs, 'body')))
}