学ぶ
エンジンクラス
HttpService
作成できません
サービス

*このコンテンツは、ベータ版のAI(人工知能)を使用して翻訳されており、エラーが含まれている可能性があります。このページを英語で表示するには、 こちら をクリックしてください。


概要
プロパティ
方法
GenerateGUID(wrapInCurlyBraces: boolean):string
GetAsync(url: Variant,nocache: boolean,headers: Variant):string
JSONDecode(input: string):Variant
JSONEncode(input: Variant):string
PostAsync(url: Variant,data: string,content_type: Enum.HttpContentType,compress: boolean,headers: Variant):string
継承されたメンバー
コードサンプル
宇宙の宇宙飛行士
local HttpService = game:GetService("HttpService")
local URL_ASTROS = "http://api.open-notify.org/astros.json"
-- エンドポイントURLにリクエストを送信します
local response = HttpService:GetAsync(URL_ASTROS)
-- JSON応答を解析します
local data = HttpService:JSONDecode(response)
-- データテーブルの情報は応答JSONに依存します
if data.message == "success" then
print("現在宇宙にいる宇宙飛行士は " .. data.number .. " 人です:")
for i, person in pairs(data.people) do
print(i .. ": " .. person.name .. " は " .. person.craft .. " にいます")
end
end
国際宇宙ステーションはどこですか?
local HttpService = game:GetService("HttpService")
-- 現在の国際宇宙ステーションはどこですか?
local URL_ISS = "http://api.open-notify.org/iss-now.json"
local function printISS()
local response
local data
-- 何かが間違った場合に備えてpcallを使用
pcall(function()
response = HttpService:GetAsync(URL_ISS)
data = HttpService:JSONDecode(response)
end)
-- リクエストが失敗したか、JSONの解析に失敗したか?
if not data then
return false
end
-- データの有効性を完全に確認します。これは、リクエストを送信しているエンドポイントによって異なります。
-- この例では、このエンドポイントが以下に記述されています: http://open-notify.org/Open-Notify-API/ISS-Location-Now/
if data.message == "success" and data.iss_position then
if data.iss_position.latitude and data.iss_position.longitude then
print("国際宇宙ステーションは現在以下の場所にあります:")
print(data.iss_position.latitude .. ", " .. data.iss_position.longitude)
return true
end
end
return false
end
if printISS() then
print("成功")
else
print("何かが間違っていました")
end
新しいPastebin投稿
local HttpService = game:GetService("HttpService")
local URL_PASTEBIN_NEW_PASTE = "https://pastebin.com/api/api_post.php"
local dataFields = {
-- Pastebin API開発者キーは
-- https://pastebin.com/api#1から取得
["api_dev_key"] = "FILL THIS WITH YOUR API DEVELOPER KEY",
["api_option"] = "paste", -- "paste"のままにしてください
["api_paste_name"] = "HttpService:PostAsync", -- ペースト名
["api_paste_code"] = "Hello, world", -- ペースト内容
["api_paste_format"] = "text", -- ペースト形式
["api_paste_expire_date"] = "10M", -- 有効期限
["api_paste_private"] = "0", -- 0=公開、1=非公開、2=プライベート
["api_user_key"] = "", -- ユーザーキー、空白の場合はゲストとして投稿
}
-- Pastebin APIはPOSTデータにURLエンコードされた文字列を使用します
-- 他のAPIはJSON、XML、または他の形式を使用するかもしれません
local data = ""
for k, v in pairs(dataFields) do
data = data .. ("&%s=%s"):format(HttpService:UrlEncode(k), HttpService:UrlEncode(v))
end
data = data:sub(2) -- 最初の&を削除します
-- これが送信するデータです
print(data)
-- リクエストを作成します
local response = HttpService:PostAsync(URL_PASTEBIN_NEW_PASTE, data, Enum.HttpContentType.ApplicationUrlEncoded, false)
-- レスポンスは新しいペーストへのURL(または何かが間違っている場合はエラーストリング)になります
print(response)
HttpService を介してオープンクラウドを開く
-- 経験設定でHTTPリクエストを有効にするのを忘れないでください!
local HttpService = game:GetService("HttpService")
local groupId = "your_group_id"
local membershipId = "your_membership_id"
local roleId = "your_role_id"
local function request()
local response = HttpService:RequestAsync({
Url = `https://apis.roblox.com/cloud/v2/groups/{groupId}/memberships/{membershipId}`, -- ユーザーのグループメンバーシップを更新します
Method = "PATCH",
Headers = {
["Content-Type"] = "application/json", -- JSONを送信するときは、これを設定してください!
["x-api-key"] = HttpService:GetSecret("APIKey"), -- Creator Hubで設定
},
Body = HttpService:JSONEncode({ role = `groups/{groupId}/roles/{roleId}` }),
})
if response.Success then
print("レスポンスは成功しました:", response.StatusCode, response.StatusMessage)
else
print("レスポンスにエラーが返されました:", response.StatusCode, response.StatusMessage)
end
print("レスポンスボディ:\n", response.Body)
print("レスポンスヘッダー:\n", HttpService:JSONEncode(response.Headers))
end
-- リクエストが失敗した場合にスクリプトが壊れないように、関数を'pcall'でラップするのを忘れないでください
local success, message = pcall(request)
if not success then
print("HTTPリクエストの送信に失敗しました:", message)
end

APIリファレンス
プロパティ
HttpEnabled
ローカルユーザーのセキュリティ
並列読み取り
機能: Network
HttpService.HttpEnabled:boolean

方法
CreateWebStreamClient
機能: Network
HttpService:CreateWebStreamClient(
streamClientType:Enum.WebStreamClientType, requestOptions:Dictionary
パラメータ
streamClientType:Enum.WebStreamClientType
requestOptions:Dictionary
コードサンプル
HttpService CreateWebStreamClient SSE
local HttpService = game:GetService("HttpService")
local URL_GEMINI_SSE = "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:streamGenerateContent?alt=sse&key="
local geminiSecret = HttpService:GetSecret("gemini_secret") -- あなたがすでに Gemini API キーをローカルシークレットとしてアップロードしていることを前提としています
local url_with_secret = geminiSecret:AddPrefix(URL_GEMINI_SSE) -- プラグインがローカルシークレットにアクセスできないことを忘れないでください!
local function handleOpen(responseStatusCode, headers)
print("ストリームが応答コードで開かれました:", responseStatusCode)
end
local function handleMessage(message)
-- ストリームのタイプに応じてイベントを解析します
print("ストリームメッセージが受信されました:", message)
end
local function request()
local sse_client = HttpService:CreateWebStreamClient(Enum.WebStreamClientType.RawStream, {
Url = url_with_secret,
Method = "POST",
Headers = {
["Content-Type"] = "application/json", -- JSON を送信する場合は、これを設定してください!
},
Body = HttpService:JSONEncode({ contents = { parts = { text ="SSE プロトコルはどのように機能しますか?" }}}),
})
local openConnection = sse_client.Opened:Connect(handleOpen)
local messageConnection = sse_client.MessageReceived:Connect(handleMessage)
sse_client.Closed:Wait()
openConnection:Disconnect()
messageConnection:Disconnect()
end
-- リクエストが失敗した場合にスクリプトが壊れないように関数を 'pcall' でラップすることを忘れないでください
local success, message = pcall(request)
if not success then
print("WebStreamClient が失敗しました:", message)
end
HttpService CreateWebStreamClient RawStream
local HttpService = game:GetService("HttpService")
local LOCAL_LLM_PORT = "http://localhost:11434/api/generate?stream=true"
local function handleMessage(message)
-- ストリームタイプに応じてイベントを解析します
-- レスポンスの Content-Type ヘッダーが JSON の場合は、次のようにデコードできます:
local json = HttpService:JSONDecode(message)
end
local function handleError(responseStatusCode, errorMessage)
print("ストリームエラー、レスポンスコード:", responseStatusCode)
end
local function request()
local sse_client = HttpService:CreateWebStreamClient(Enum.WebStreamClientType.RawStream, {
-- Ollama を使用してローカルで実行されている Llama3.2 LLM サーバー
Url = LOCAL_LLM_PORT,
Method = "POST",
Headers = {
["Content-Type"] = "application/json", -- JSON を送信する場合は、これを設定してください!
},
Body = HttpService:JSONEncode({ model="llama3.2", prompt ="面白いジョークを教えてください"}),
})
local messageConnection = sse_client.MessageReceived:Connect(handleMessage)
local errorConnection = sse_client.Error:Connect(handleError)
sse_client.Closed:Wait()
messageConnection:Disconnect()
errorConnection:Disconnect()
sse_client:close()
end
-- リクエストが失敗した場合にスクリプトが壊れないように関数を 'pcall' でラップすることを忘れないでください
local success, message = pcall(request)
if not success then
print("WebStreamClient が失敗しました:", message)
end

GenerateGUID
並列書き込み
HttpService:GenerateGUID(wrapInCurlyBraces:boolean):string
パラメータ
wrapInCurlyBraces:boolean
既定値: true
戻り値
コードサンプル
HttpService GenerateGUID
local HttpService = game:GetService("HttpService")
local result = HttpService:GenerateGUID(true)
print(result) --> 出力例: {4c50eba2-d2ed-4d79-bec1-02a967f49c58}

GetAsync
イールド
機能: Network
HttpService:GetAsync(
url:Variant, nocache:boolean, headers:Variant
パラメータ
url:Variant
nocache:boolean
既定値: false
headers:Variant
戻り値
コードサンプル
宇宙の宇宙飛行士
local HttpService = game:GetService("HttpService")
local URL_ASTROS = "http://api.open-notify.org/astros.json"
-- エンドポイントURLにリクエストを送信します
local response = HttpService:GetAsync(URL_ASTROS)
-- JSON応答を解析します
local data = HttpService:JSONDecode(response)
-- データテーブルの情報は応答JSONに依存します
if data.message == "success" then
print("現在宇宙にいる宇宙飛行士は " .. data.number .. " 人です:")
for i, person in pairs(data.people) do
print(i .. ": " .. person.name .. " は " .. person.craft .. " にいます")
end
end
国際宇宙ステーションはどこですか?
local HttpService = game:GetService("HttpService")
-- 現在の国際宇宙ステーションはどこですか?
local URL_ISS = "http://api.open-notify.org/iss-now.json"
local function printISS()
local response
local data
-- 何かが間違った場合に備えてpcallを使用
pcall(function()
response = HttpService:GetAsync(URL_ISS)
data = HttpService:JSONDecode(response)
end)
-- リクエストが失敗したか、JSONの解析に失敗したか?
if not data then
return false
end
-- データの有効性を完全に確認します。これは、リクエストを送信しているエンドポイントによって異なります。
-- この例では、このエンドポイントが以下に記述されています: http://open-notify.org/Open-Notify-API/ISS-Location-Now/
if data.message == "success" and data.iss_position then
if data.iss_position.latitude and data.iss_position.longitude then
print("国際宇宙ステーションは現在以下の場所にあります:")
print(data.iss_position.latitude .. ", " .. data.iss_position.longitude)
return true
end
end
return false
end
if printISS() then
print("成功")
else
print("何かが間違っていました")
end

GetSecret
並列書き込み
機能: Network
HttpService:GetSecret(key:string):Secret
パラメータ
key:string
戻り値

JSONDecode
並列書き込み
HttpService:JSONDecode(input:string):Variant
パラメータ
input:string
戻り値
Variant
コードサンプル
HttpService JSONDecode
local HttpService = game:GetService("HttpService")
local jsonString = [[
{
"message": "success",
"info": {
"points": 120,
"isLeader": true,
"user": {
"id": 12345,
"name": "JohnDoe"
},
"past_scores": [50, 42, 95],
"best_friend": null
}
}
]]
local data = HttpService:JSONDecode(jsonString)
if data.message == "success" then
-- tab["hello"] と tab.hello は同等なので、
-- ここで data["info"]["points"] を使用することもできます:
print("私には " .. data.info.points .. " ポイントあります")
if data.info.isLeader then
print("私はリーダーです")
end
print("私は " .. #data.info.past_scores .. " 回の過去のスコアがあります")
print("すべての情報:")
for key, value in pairs(data.info) do
print(key, typeof(value), value)
end
end

JSONEncode
並列書き込み
HttpService:JSONEncode(input:Variant):string
パラメータ
input:Variant
戻り値
コードサンプル
HttpService JSONEncode
local HttpService = game:GetService("HttpService")
local tab = {
-- 注意: これらの行は等価です
--["message"] = "成功",
message = "成功",
info = {
points = 123,
isLeader = true,
user = {
id = 12345,
name = "JohnDoe",
},
past_scores = { 50, 42, 95 },
best_friend = nil,
},
}
local json = HttpService:JSONEncode(tab)
print(json)

PostAsync
イールド
機能: Network
HttpService:PostAsync(
url:Variant, data:string, content_type:Enum.HttpContentType, compress:boolean, headers:Variant
パラメータ
url:Variant
data:string
既定値: "ApplicationJson"
compress:boolean
既定値: false
headers:Variant
戻り値
コードサンプル
新しいPastebin投稿
local HttpService = game:GetService("HttpService")
local URL_PASTEBIN_NEW_PASTE = "https://pastebin.com/api/api_post.php"
local dataFields = {
-- Pastebin API開発者キーは
-- https://pastebin.com/api#1から取得
["api_dev_key"] = "FILL THIS WITH YOUR API DEVELOPER KEY",
["api_option"] = "paste", -- "paste"のままにしてください
["api_paste_name"] = "HttpService:PostAsync", -- ペースト名
["api_paste_code"] = "Hello, world", -- ペースト内容
["api_paste_format"] = "text", -- ペースト形式
["api_paste_expire_date"] = "10M", -- 有効期限
["api_paste_private"] = "0", -- 0=公開、1=非公開、2=プライベート
["api_user_key"] = "", -- ユーザーキー、空白の場合はゲストとして投稿
}
-- Pastebin APIはPOSTデータにURLエンコードされた文字列を使用します
-- 他のAPIはJSON、XML、または他の形式を使用するかもしれません
local data = ""
for k, v in pairs(dataFields) do
data = data .. ("&%s=%s"):format(HttpService:UrlEncode(k), HttpService:UrlEncode(v))
end
data = data:sub(2) -- 最初の&を削除します
-- これが送信するデータです
print(data)
-- リクエストを作成します
local response = HttpService:PostAsync(URL_PASTEBIN_NEW_PASTE, data, Enum.HttpContentType.ApplicationUrlEncoded, false)
-- レスポンスは新しいペーストへのURL(または何かが間違っている場合はエラーストリング)になります
print(response)

RequestAsync
イールド
機能: Network
HttpService:RequestAsync(requestOptions:Dictionary):Dictionary
パラメータ
requestOptions:Dictionary
戻り値
コードサンプル
HTTPリクエストの送信
-- 経験設定でHTTPリクエストを有効に設定することを忘れないでください!
local HttpService = game:GetService("HttpService")
local function request()
local response = HttpService:RequestAsync({
Url = "http://httpbin.org/post", -- このウェブサイトはHTTPリクエストのデバッグに役立ちます
Method = "POST",
Headers = {
["Content-Type"] = "application/json", -- JSONを送信する場合、これを設定してください!
},
Body = HttpService:JSONEncode({ hello = "world" }),
})
if response.Success then
print("ステータスコード:", response.StatusCode, response.StatusMessage)
print("レスポンスボディ:\n", response.Body)
else
print("リクエストが失敗しました:", response.StatusCode, response.StatusMessage)
end
end
-- リクエストが失敗した場合にスクリプトが壊れないように関数を'pcall'でラップすることを忘れないでください
local success, message = pcall(request)
if not success then
print("Httpリクエストが失敗しました:", message)
end
HttpService を介してオープンクラウドを開く
-- 経験設定でHTTPリクエストを有効にするのを忘れないでください!
local HttpService = game:GetService("HttpService")
local groupId = "your_group_id"
local membershipId = "your_membership_id"
local roleId = "your_role_id"
local function request()
local response = HttpService:RequestAsync({
Url = `https://apis.roblox.com/cloud/v2/groups/{groupId}/memberships/{membershipId}`, -- ユーザーのグループメンバーシップを更新します
Method = "PATCH",
Headers = {
["Content-Type"] = "application/json", -- JSONを送信するときは、これを設定してください!
["x-api-key"] = HttpService:GetSecret("APIKey"), -- Creator Hubで設定
},
Body = HttpService:JSONEncode({ role = `groups/{groupId}/roles/{roleId}` }),
})
if response.Success then
print("レスポンスは成功しました:", response.StatusCode, response.StatusMessage)
else
print("レスポンスにエラーが返されました:", response.StatusCode, response.StatusMessage)
end
print("レスポンスボディ:\n", response.Body)
print("レスポンスヘッダー:\n", HttpService:JSONEncode(response.Headers))
end
-- リクエストが失敗した場合にスクリプトが壊れないように、関数を'pcall'でラップするのを忘れないでください
local success, message = pcall(request)
if not success then
print("HTTPリクエストの送信に失敗しました:", message)
end

UrlEncode
並列書き込み
機能: Network
HttpService:UrlEncode(input:string):string
パラメータ
input:string
戻り値
コードサンプル
HttpService UrlEncode
local HttpService = game:GetService("HttpService")
local content = "Je suis allé au cinéma." -- フランス語で「映画に行きました」
local result = HttpService:UrlEncode(content)
print(result) --> Je%20suis%20all%C3%A9%20au%20cinema%2E
新しいPastebin投稿
local HttpService = game:GetService("HttpService")
local URL_PASTEBIN_NEW_PASTE = "https://pastebin.com/api/api_post.php"
local dataFields = {
-- Pastebin API開発者キーは
-- https://pastebin.com/api#1から取得
["api_dev_key"] = "FILL THIS WITH YOUR API DEVELOPER KEY",
["api_option"] = "paste", -- "paste"のままにしてください
["api_paste_name"] = "HttpService:PostAsync", -- ペースト名
["api_paste_code"] = "Hello, world", -- ペースト内容
["api_paste_format"] = "text", -- ペースト形式
["api_paste_expire_date"] = "10M", -- 有効期限
["api_paste_private"] = "0", -- 0=公開、1=非公開、2=プライベート
["api_user_key"] = "", -- ユーザーキー、空白の場合はゲストとして投稿
}
-- Pastebin APIはPOSTデータにURLエンコードされた文字列を使用します
-- 他のAPIはJSON、XML、または他の形式を使用するかもしれません
local data = ""
for k, v in pairs(dataFields) do
data = data .. ("&%s=%s"):format(HttpService:UrlEncode(k), HttpService:UrlEncode(v))
end
data = data:sub(2) -- 最初の&を削除します
-- これが送信するデータです
print(data)
-- リクエストを作成します
local response = HttpService:PostAsync(URL_PASTEBIN_NEW_PASTE, data, Enum.HttpContentType.ApplicationUrlEncoded, false)
-- レスポンスは新しいペーストへのURL(または何かが間違っている場合はエラーストリング)になります
print(response)

©2026 Roblox Corporation。Roblox(ロブロックス)、RobloxロゴおよびPowering Imaginationは、米国並びにその他の国における登録商標および非登録商標です。