HTTP Request via Schema
Bổ sung các trường vào schema GraphQL để truy xuất dữ liệu yêu cầu HTTP hiện tại.
Danh sách các trường
Các trường sau được thêm vào schema:
_httpRequestBody
Nội dung của yêu cầu HTTP.
_httpRequestClientHost
Host của client.
_httpRequestClientIP
Truy xuất địa chỉ IP của client. Nếu máy chủ không được cấu hình đúng (xem bên dưới), phản hồi sẽ là null.
Cấu hình
Địa chỉ IP của client được truy xuất từ biến toàn cục $_SERVER, thông thường từ thuộc tính 'REMOTE_ADDR'. Tuy nhiên, các nền tảng khác nhau có thể yêu cầu sử dụng tên thuộc tính khác để lấy thông tin này.
Ví dụ:
- Cloudflare có thể dùng
'HTTP_CF_CONNECTING_IP' - AWS có thể dùng
'HTTP_X_FORWARDED_FOR'
Tên thuộc tính cần sử dụng có thể được cấu hình trong tab "Plugin Configuration > Server IP Configuration" trên trang Cài đặt:

_httpRequestCookie
Giá trị cookie của yêu cầu.
_httpRequestCookies
Các cookie của yêu cầu.
_httpRequestDomain
Tên miền của URL được yêu cầu.
_httpRequestFullURL
URL được yêu cầu (bao gồm các tham số query).
_httpRequestHasCookie
Yêu cầu có chứa một cookie nhất định không?
_httpRequestHasHeader
Yêu cầu có chứa một header nhất định không?
_httpRequestHasParam
Yêu cầu có chứa một tham số nhất định không?
_httpRequestHeader
Giá trị của một header trong yêu cầu.
_httpRequestHeaders
Các header của yêu cầu.
_httpRequestHost
Host của URL được yêu cầu.
_httpRequestMethod
Phương thức của yêu cầu.
_httpRequestParams
Đối tượng JSON chứa tất cả các tham số (được truyền qua POST hoặc GET).
Giá trị tham số có thể là:
- Chuỗi:
?param=value - Mảng:
?someArray[]=1&someArray[]=2 - Mảng của mảng:
?someMatrix[0][0]=3&someMatrix[0][1]=4&someMatrix[1][0]=5&someMatrix[1][1]=6 - Mảng kết hợp (tức là đối tượng):
?someAssocArray["admins"]=20&someAssocArray["authors"]=30 - Mảng kết hợp của mảng:
?someAssocMatrix["admins"][0]=7&someAssocMatrix["admins"][1]=8&someAssocMatrix["authors"][0]=9&someAssocMatrix["authors"][1]=10 - Các kết hợp khác
Để lấy giá trị của tham số, chúng ta có thể dùng các trường _httpRequestStringParam và _httpRequestStringListParam cho hai trường hợp đầu tiên tương ứng, nhưng không có trường nào cho các trường hợp còn lại.
Đối với những trường hợp đó, hãy dùng trường _httpRequestParams để lấy đối tượng JSON, sau đó truy xuất giá trị tương ứng từ bên trong.
_httpRequestProtocol
Giao thức của yêu cầu.
_httpRequestQuery
Chuỗi tham số query.
_httpRequestReferer
Referer của yêu cầu.
_httpRequestRequestTime
Dấu thời gian của thời điểm bắt đầu yêu cầu.
_httpRequestScheme
Scheme của URL được yêu cầu.
_httpRequestServerIP
Địa chỉ IP của máy chủ.
_httpRequestStringListParam
Giá trị của một tham số (được truyền qua POST hoặc GET) theo dạng ?param[]=value1¶m[]=value2.
_httpRequestStringParam
Giá trị của một tham số (được truyền qua POST hoặc GET) theo dạng ?param=value.
_httpRequestURL
URL được yêu cầu (không có tham số query).
_httpRequestURLPath
Đường dẫn tuyệt đối (bắt đầu bằng "/") của URL được yêu cầu.
_httpRequestUserAgent
User agent.
Ví dụ
Query này:
query {
_httpRequestHeaders
existingHeader: _httpRequestHeader(name: "Accept")
caseInsensitiveExistingHeader: _httpRequestHeader(name: "accept")
nonExistingHeader: _httpRequestHeader(name: "Non-existing")
existingHasHeader: _httpRequestHasHeader(name: "Accept")
caseInsensitiveExistingHasHeader: _httpRequestHasHeader(name: "accept")
nonExistingHasHeader: _httpRequestHasHeader(name: "Non-existing")
_httpRequestBody
_httpRequestMethod
_httpRequestDomain
_httpRequestScheme
_httpRequestHost
_httpRequestURL
_httpRequestFullURL
_httpRequestURLPath
_httpRequestQuery
_httpRequestParams
existingParam: _httpRequestStringParam(name: "page")
caseInsensitiveExistingParam: _httpRequestStringParam(name: "PAge")
existingArrayParam: _httpRequestStringListParam(name: "someArray")
nonExistingParam: _httpRequestStringParam(name: "also-non-existing")
nonExistingListParam: _httpRequestStringListParam(name: "also-non-existing")
existingHasParam: _httpRequestHasParam(name: "page")
caseInsensitiveExistingHasParam: _httpRequestHasParam(name: "PAge")
nonExistingHasParam: _httpRequestHasParam(name: "also-non-existing")
existingCookie: _httpRequestCookie(name: "wordpress_test_cookie")
caseInsentiveExistingCookie: _httpRequestCookie(name: "Wordpress_Test_Cookie")
nonExistingCookie: _httpRequestCookie(name: "not_existing")
existingHasCookie: _httpRequestHasCookie(name: "wordpress_test_cookie")
caseInsentiveExistingHasCookie: _httpRequestHasCookie(name: "Wordpress_Test_Cookie")
nonExistingHasCookie: _httpRequestHasCookie(name: "not_existing")
_httpRequestProtocol
_httpRequestReferer
_httpRequestServerIP
_httpRequestClientIP
_httpRequestClientHost
_httpRequestUserAgent
_httpRequestCookies
_httpRequestRequestTime
}...trả về:
{
"data": {
"_httpRequestHeaders": {
"authorization": "",
"host": "gato-graphql-pro.lndo.site",
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/114.0",
"content-length": "1924",
"accept": "application/json",
"accept-encoding": "gzip, deflate, br",
"accept-language": "en-US,en;q=0.5",
"content-type": "application/json",
"cookie": "wordpress_sec_f21902903273c44cc3a47d07e23af599=admin%7C1687924210%7CcMlLArK65w5nACJHlglLMMd52rRVZRmu2LRUJmCi7n1%7Cad6b03a20093f342a4107076432f7857e244174ab4d866c1887417c2e304e3fe; wp-settings-time-1=1686559494; wp-settings-1=libraryContent%3Dbrowse; wordpress_test_cookie=WP%20Cookie%20check; wp_lang=en_US; wordpress_logged_in_f21902903273c44cc3a47d07e23af599=admin%7C1687924210%7CcMlLArK65w5nACJHlglLMMd52rRVZRmu2LRUJmCi7n1%7C0ec85ac4a275aff3c464e139d40061aa0062a4e7376666b99ec8063a6715788a",
"dnt": "1",
"origin": "https://gato-graphql-pro.lndo.site",
"referer": "https://gato-graphql-pro.lndo.site/wp-admin/admin.php?page=gatographql&query=%7B%0A%20%20_httpRequestHeaders%0A%20%20existingHeader%3A%20_httpRequestHeader(name%3A%20%22Accept%22)%0A%20%20caseInsensitiveExistingHeader%3A%20_httpRequestHeader(name%3A%20%22accept%22)%0A%20%20nonExistingHeader%3A%20_httpRequestHeader(name%3A%20%22Non-existing%22)%0A%20%20existingHasHeader%3A%20_httpRequestHasHeader(name%3A%20%22Accept%22)%0A%20%20caseInsensitiveExistingHasHeader%3A%20_httpRequestHasHeader(name%3A%20%22accept%22)%0A%20%20nonExistingHasHeader%3A%20_httpRequestHasHeader(name%3A%20%22Non-existing%22)%0A%20%20_httpRequestBody%0A%20%20_httpRequestMethod%0A%20%20_httpRequestDomain%0A%20%20_httpRequestScheme%0A%20%20_httpRequestHost%0A%20%20_httpRequestURL%0A%20%20_httpRequestFullURL%0A%20%20_httpRequestURLPath%0A%20%20_httpRequestQuery%0A%20%20_httpRequestParams%0A%20%20existingParam%3A%20_httpRequestStringParam(name%3A%20%22page%22)%0A%20%20caseInsensitiveExistingParam%3A%20_httpRequestStringParam(name%3A%20%22PAge%22)%0A%20%20existingArrayParam%3A%20_httpRequestStringListParam(name%3A%20%22someArray%22)%0A%20%20nonExistingParam%3A%20_httpRequestStringParam(name%3A%20%22also-non-existing%22)%0A%20%20nonExistingListParam%3A%20_httpRequestStringListParam(name%3A%20%22also-non-existing%22)%0A%20%20existingHasParam%3A%20_httpRequestHasParam(name%3A%20%22page%22)%0A%20%20caseInsensitiveExistingHasParam%3A%20_httpRequestHasParam(name%3A%20%22PAge%22)%0A%20%20nonExistingHasParam%3A%20_httpRequestHasParam(name%3A%20%22also-non-existing%22)%0A%20%20existingCookie%3A%20_httpRequestCookie(name%3A%20%22wordpress_test_cookie%22)%0A%20%20caseInsentiveExistingCookie%3A%20_httpRequestCookie(name%3A%20%22Wordpress_Test_Cookie%22)%0A%20%20nonExistingCookie%3A%20_httpRequestCookie(name%3A%20%22not_existing%22)%0A%20%20existingHasCookie%3A%20_httpRequestHasCookie(name%3A%20%22wordpress_test_cookie%22)%0A%20%20caseInsentiveExistingHasCookie%3A%20_httpRequestHasCookie(name%3A%20%22Wordpress_Test_Cookie%22)%0A%20%20nonExistingHasCookie%3A%20_httpRequestHasCookie(name%3A%20%22not_existing%22)%0A%20%20_httpRequestProtocol%0A%20%20_httpRequestReferer%0A%20%20_httpRequestServerIP%0A%20%20_httpRequestClientIP%0A%20%20_httpRequestClientHost%0A%20%20_httpRequestUserAgent%0A%0A%20%20_httpRequestCookies%0A%20%20_httpRequestRequestTime%0A%7D&variables=%7B%2B%2B%22postID%22%3A%2B40%2C%2B%2B%22translateToLang%22%3A%2B%22es%22%7D&operationName=SendEmail",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin",
"sec-gpc": "1",
"te": "trailers",
"x-forwarded-for": "172.19.0.1",
"x-forwarded-host": "gato-graphql-pro.lndo.site",
"x-forwarded-port": "443",
"x-forwarded-proto": "https",
"x-forwarded-server": "6de0a38d2bbe",
"x-lando": "on",
"x-real-ip": "172.19.0.1",
"x-wp-nonce": "258a8aed3b"
},
"existingHeader": "application/json",
"caseInsensitiveExistingHeader": "application/json",
"nonExistingHeader": null,
"existingHasHeader": true,
"caseInsensitiveExistingHasHeader": true,
"nonExistingHasHeader": false,
"_httpRequestBody": "{\"query\":\"{\\n _httpRequestHeaders\\n existingHeader: _httpRequestHeader(name: \\\"Accept\\\")\\n caseInsensitiveExistingHeader: _httpRequestHeader(name: \\\"accept\\\")\\n nonExistingHeader: _httpRequestHeader(name: \\\"Non-existing\\\")\\n existingHasHeader: _httpRequestHasHeader(name: \\\"Accept\\\")\\n caseInsensitiveExistingHasHeader: _httpRequestHasHeader(name: \\\"accept\\\")\\n nonExistingHasHeader: _httpRequestHasHeader(name: \\\"Non-existing\\\")\\n _httpRequestBody\\n _httpRequestMethod\\n _httpRequestDomain\\n _httpRequestScheme\\n _httpRequestHost\\n _httpRequestURL\\n _httpRequestFullURL\\n _httpRequestURLPath\\n _httpRequestQuery\\n _httpRequestParams\\n existingParam: _httpRequestStringParam(name: \\\"page\\\")\\n caseInsensitiveExistingParam: _httpRequestStringParam(name: \\\"PAge\\\")\\n existingArrayParam: _httpRequestStringListParam(name: \\\"someArray\\\")\\n nonExistingParam: _httpRequestStringParam(name: \\\"also-non-existing\\\")\\n nonExistingListParam: _httpRequestStringListParam(name: \\\"also-non-existing\\\")\\n existingHasParam: _httpRequestHasParam(name: \\\"page\\\")\\n caseInsensitiveExistingHasParam: _httpRequestHasParam(name: \\\"PAge\\\")\\n nonExistingHasParam: _httpRequestHasParam(name: \\\"also-non-existing\\\")\\n existingCookie: _httpRequestCookie(name: \\\"wordpress_test_cookie\\\")\\n caseInsentiveExistingCookie: _httpRequestCookie(name: \\\"Wordpress_Test_Cookie\\\")\\n nonExistingCookie: _httpRequestCookie(name: \\\"not_existing\\\")\\n existingHasCookie: _httpRequestHasCookie(name: \\\"wordpress_test_cookie\\\")\\n caseInsentiveExistingHasCookie: _httpRequestHasCookie(name: \\\"Wordpress_Test_Cookie\\\")\\n nonExistingHasCookie: _httpRequestHasCookie(name: \\\"not_existing\\\")\\n _httpRequestProtocol\\n _httpRequestReferer\\n _httpRequestServerIP\\n _httpRequestClientIP\\n _httpRequestClientHost\\n _httpRequestUserAgent\\n\\n _httpRequestCookies\\n _httpRequestRequestTime\\n}\",\"variables\":{\"postID\":40,\"translateToLang\":\"es\"}}",
"_httpRequestMethod": "POST",
"_httpRequestDomain": "lndo.site",
"_httpRequestScheme": "https",
"_httpRequestHost": "gato-graphql-pro.lndo.site",
"_httpRequestURL": "https://gato-graphql-pro.lndo.site/wp-admin/edit.php",
"_httpRequestFullURL": "https://gato-graphql-pro.lndo.site/wp-admin/edit.php?page=gatographql&action=run_query",
"_httpRequestURLPath": "/wp-admin/edit.php",
"_httpRequestQuery": "page=gatographql&action=run_query",
"_httpRequestParams": {
"page": "gatographql",
"action": "run_query"
},
"existingParam": "gatographql",
"caseInsensitiveExistingParam": null,
"existingArrayParam": null,
"nonExistingParam": null,
"nonExistingListParam": null,
"existingHasParam": true,
"caseInsensitiveExistingHasParam": false,
"nonExistingHasParam": false,
"existingCookie": "WP Cookie check",
"caseInsentiveExistingCookie": null,
"nonExistingCookie": null,
"existingHasCookie": true,
"caseInsentiveExistingHasCookie": false,
"nonExistingHasCookie": false,
"_httpRequestProtocol": "HTTP/1.1",
"_httpRequestReferer": "https://gato-graphql-pro.lndo.site/wp-admin/admin.php?page=gatographql&query=%7B%0A%20%20_httpRequestHeaders%0A%20%20existingHeader%3A%20_httpRequestHeader(name%3A%20%22Accept%22)%0A%20%20caseInsensitiveExistingHeader%3A%20_httpRequestHeader(name%3A%20%22accept%22)%0A%20%20nonExistingHeader%3A%20_httpRequestHeader(name%3A%20%22Non-existing%22)%0A%20%20existingHasHeader%3A%20_httpRequestHasHeader(name%3A%20%22Accept%22)%0A%20%20caseInsensitiveExistingHasHeader%3A%20_httpRequestHasHeader(name%3A%20%22accept%22)%0A%20%20nonExistingHasHeader%3A%20_httpRequestHasHeader(name%3A%20%22Non-existing%22)%0A%20%20_httpRequestBody%0A%20%20_httpRequestMethod%0A%20%20_httpRequestDomain%0A%20%20_httpRequestScheme%0A%20%20_httpRequestHost%0A%20%20_httpRequestURL%0A%20%20_httpRequestFullURL%0A%20%20_httpRequestURLPath%0A%20%20_httpRequestQuery%0A%20%20_httpRequestParams%0A%20%20existingParam%3A%20_httpRequestStringParam(name%3A%20%22page%22)%0A%20%20caseInsensitiveExistingParam%3A%20_httpRequestStringParam(name%3A%20%22PAge%22)%0A%20%20existingArrayParam%3A%20_httpRequestStringListParam(name%3A%20%22someArray%22)%0A%20%20nonExistingParam%3A%20_httpRequestStringParam(name%3A%20%22also-non-existing%22)%0A%20%20nonExistingListParam%3A%20_httpRequestStringListParam(name%3A%20%22also-non-existing%22)%0A%20%20existingHasParam%3A%20_httpRequestHasParam(name%3A%20%22page%22)%0A%20%20caseInsensitiveExistingHasParam%3A%20_httpRequestHasParam(name%3A%20%22PAge%22)%0A%20%20nonExistingHasParam%3A%20_httpRequestHasParam(name%3A%20%22also-non-existing%22)%0A%20%20existingCookie%3A%20_httpRequestCookie(name%3A%20%22wordpress_test_cookie%22)%0A%20%20caseInsentiveExistingCookie%3A%20_httpRequestCookie(name%3A%20%22Wordpress_Test_Cookie%22)%0A%20%20nonExistingCookie%3A%20_httpRequestCookie(name%3A%20%22not_existing%22)%0A%20%20existingHasCookie%3A%20_httpRequestHasCookie(name%3A%20%22wordpress_test_cookie%22)%0A%20%20caseInsentiveExistingHasCookie%3A%20_httpRequestHasCookie(name%3A%20%22Wordpress_Test_Cookie%22)%0A%20%20nonExistingHasCookie%3A%20_httpRequestHasCookie(name%3A%20%22not_existing%22)%0A%20%20_httpRequestProtocol%0A%20%20_httpRequestReferer%0A%20%20_httpRequestServerIP%0A%20%20_httpRequestClientIP%0A%20%20_httpRequestClientHost%0A%20%20_httpRequestUserAgent%0A%0A%20%20_httpRequestCookies%0A%20%20_httpRequestRequestTime%0A%7D&variables=%7B%2B%2B%22postID%22%3A%2B40%2C%2B%2B%22translateToLang%22%3A%2B%22es%22%7D&operationName=SendEmail",
"_httpRequestServerIP": "172.19.0.4",
"_httpRequestClientIP": "172.19.0.2",
"_httpRequestClientHost": null,
"_httpRequestUserAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/114.0",
"_httpRequestCookies": {
"wordpress_sec_f21902903273c44cc3a47d07e23af599": "admin|1687924210|cMlLArK65w5nACJHlglLMMd52rRVZRmu2LRUJmCi7n1|ad6b03a20093f342a4107076432f7857e244174ab4d866c1887417c2e304e3fe",
"wp-settings-time-1": "1686559494",
"wp-settings-1": "libraryContent=browse",
"wordpress_test_cookie": "WP Cookie check",
"wp_lang": "en_US",
"wordpress_logged_in_f21902903273c44cc3a47d07e23af599": "admin|1687924210|cMlLArK65w5nACJHlglLMMd52rRVZRmu2LRUJmCi7n1|0ec85ac4a275aff3c464e139d40061aa0062a4e7376666b99ec8063a6715788a"
},
"_httpRequestRequestTime": 1687836456
}
}