ไวยากรณ์
request(options: RequestOptions): Response | stringAliases
http_requesthttp.requestArguments
| ชื่อ | ชนิด | คำอธิบาย |
|---|---|---|
options | RequestOptions | ตารางการตั้งค่าเสริมที่ควบคุมลักษณะการทำงาน |
Returns
| ชื่อ | ชนิด | คำอธิบาย |
|---|---|---|
response | Response | string | ตารางตอบกลับ HTTP หรือสตริงความเข้ากันได้ |
คำอธิบาย
ส่งคำขอ HTTP พร้อมด้วยตัวเลือกเมธอด ส่วนหัว เนื้อหา และระยะหมดเวลา
เรียกด้วย parameter 1 ค่า: options ตาราง arguments อธิบายค่าที่จำเป็นและค่าที่ปรับพฤติกรรม
ส่งคืน response (Response | string) ใช้ตาราง returns เพื่อแยกค่าที่สำเร็จ ผลลัพธ์ nil และ error ที่จัดการต่อได้
ตัวอย่าง
ส่งคำขอ 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)
endTypes
RequestOptions
กำหนดการร้องขอ HTTP
Url string URL ปลายทาง HTTP หรือ HTTPSMethod? "GET" | "POST" | "PUT" | "PATCH" | "DELETE" วิธี HTTP ที่ใช้สำหรับการร้องขอHeaders? {[string]: string} ส่วนหัวคำขอเพิ่มเติมCookies? {[string]: string} เพิ่มคุกกี้ในคำขอขาออกBody? string เนื้อความคำขอดิบ