Skip to content
Mistium edited this page Oct 20, 2024 · 14 revisions

HTTP Request Commands

New methods documentation:

https://osl.mistium.com/methods/networking

DO NOT USE THE OLD COMMANDS SYNTAX, everything that these commands used to do can now be done simpler and easier with methods

Example:

Send to a discord webhook through osl

http "new"
http "method" "POST"
http "type" "application/json"
body = {}
body.key("content") = ""
http "body" body
http "sendto" "https://discord.com/api/webhooks/"

Sending an HTTP Request in One Line

Description

Sends a complete HTTP request in a single line, specifying the method, body, and URL.

Example

http "method" "body" "url"

new

Description

Resets the current HTTP data, clearing any previously set values for method, type, body, and URL.

Example

http "new"

method

Description

Sets the currently used HTTP method for the request.

Parameters

  • "get": HTTP GET method
  • "post": HTTP POST method
  • "put": HTTP PUT method
  • "delete": HTTP DELETE method
  • "patch": HTTP PATCH method
  • ... (other HTTP methods)

Example

http "method" "get"

headers

Description

Sets the currently used headers for the request.

Example

http "headers" {}

getheaders

(v4.7.4 and above)

Description

Gets the currently used headers for the request.

Returns as a json object

Example

http "getheaders"
say data

setheader

(v4.7.4 and above)

Description

Sets a single header key and value

Example

http "setheader" "key" "value"

type

Description

Sets the currently used request type or content type.

Parameters

  • "text/plain": Plain text
  • "application/json": JSON data
  • "application/xml": XML data
  • ... (other content types)

Example

http "type" "text/plain"

body

Description

Sets the body content for the HTTP request.

Parameters

  • Specify the content of the request body.

Example

http "body" "content goes here"

sendto

Description

Sends the HTTP request to the specified URL.

Parameters

  • Provide the target URL where the request should be sent.

Example

http "sendto" "https://example.com/api/resource"

You need v4.7.4 or later to use the below variables:

response_code response_success response_failed response_error


get_response

Description

Grabs the response from the website and sets the variable called "response" to the response value.

Example

http "get_response"

if response != null (
  if response_code == 404 (
    say "404: Not Found"
  ) else (
    if response_success (
      say response
      // Your code to run if there is a response
    )
  )
)

This command also sets response_error


wait_response

Description

Waits for a response from the website and sets the variable called "response" to the response value.

Example

http "wait_response"

if response_code == 404 (
  say "404: Not Found"
) else (
  if response_success (
    say response
    // Your code to run if there is a response
  )
)

This command also sets response_error


Note: These commands are designed to assist in making HTTP requests and handling responses in a scripted environment. Ensure proper error handling and security measures are implemented in a real-world scenario.

originOS Wiki

Wiki Views:
:views

OSL | RSH | ICN

Clone this wiki locally