유틸리티

request

메서드, 헤더, 본문, 시간 초과 옵션이 포함된 HTTP 요청을 보냅니다.

문법

request(options: RequestOptions): Response | string
별칭 http_requesthttp.request

인수

이름타입설명
optionsRequestOptions작업 작동 방식을 제어하는 선택적 설정 테이블입니다.

반환값

이름타입설명
responseResponse | stringHTTP 응답 테이블 또는 호환성 문자열입니다.

설명

메서드, 헤더, 본문, 시간 초과 옵션이 포함된 HTTP 요청을 보냅니다.

1개 파라미터로 호출합니다: options. 인수 표는 필수 값과 동작을 조정하는 값을 설명합니다.

response (Response | string)을 반환합니다. 반환 표를 사용해 성공 값, nil 결과, 복구 가능한 오류를 구분하세요.

예제

JSON 요청을 보내고 공개 응답 필드를 검사합니다.

local response = request({
    Url = "https://example.com/api/status",
    Method = "GET",
    Headers = {
        ["Accept"] = "application/json",
    },
})

if type(response) == "table" then
    if response.Success then
        print(response.StatusCode, response.Body)
    else
        warn(response.StatusMessage)
    end
else
    warn(response)
end

타입

RequestOptions

HTTP 요청을 정의합니다.

Url string HTTP 또는 HTTPS 대상 URL입니다.Method? "GET" | "POST" | "PUT" | "PATCH" | "DELETE" 요청에 사용되는 HTTP 메서드입니다.Headers? {[string]: string} 추가 요청 헤더.Cookies? {[string]: string} 나가는 요청에 쿠키가 추가되었습니다.Body? string 원시 요청 본문.