"this is magic" - Nvw 2017
this resource provides a client-side code HTTP client for GTA: Network.
this does not supply you with an HTTP client on the server. use included C# tools. you may use this resource as a weak reference for doing this, though.
-
your game server must be running .NET 4.5 or newer.
-
clone this repo into your server's
resources
folder. -
add
<resource src="clienthttp" />
to your settings.xml -
optionally install require (it's cool, i swear!)
-
done!
This closely, but not perfectly, follows the WHATWG Fetch API spec. There's not a lot to cover that other widely-available documentation sources already don't.
All of the documentation on how to use this function is here: https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch
Example, using require
let fetch
API.onResourceStart.connect(() => {
const { require } = exported.require.require
fetch = require('clienthttp').fetch
fetch('https://httpbin.org/user-agent').then((response) => {
return response.json()
}).then((data) => {
API.sendChatMessage(`The your user agent is ${data['user-agent']}`)
})
})
let fetch
API.onResourceStart.connect(() => {
fetch = exported.clienthttp.clienthttp.fetch
fetch('https://httpbin.org/user-agent').then((response) => {
return response.json()
}).then((data) => {
API.sendChatMessage(`The your user agent is ${data['user-agent']}`)
})
})
soon
This resource only allows you to receive text or json data.
If you need XML, or any other, you can open a PR or write a conversion library from Response.text()
. This is literally what the JSON return does.