Proxyman
HomepageDownload
  • Overview
  • Changelog
  • License
  • License Manager
  • Raycast
  • Command-line
  • Security Compliance
  • Proxyman iOS
    • Proxyman for iOS
    • Map Local for iOS
    • Breakpoint for iOS
    • Tutorial for iOS
      • Map Local for iOS Tutorial
      • Breakpoint for iOS Tutorial
  • Debug on Devices
    • macOS
    • iOS Device
    • iOS Simulator
    • tvOS & watchOS
    • Android Device & Emulator
      • Automatic Script for Android Emulator
      • Sample Android Project
    • Firefox
    • Java VMs
    • Python
    • Ruby
    • NodeJS
    • Rust
    • Golang
    • React Native
    • Flutter
    • HTTP Clients
    • Docker
    • ElectronJS
    • NextJS (fetch)
  • Automatic Setup
    • Automatic Setup
    • Manual Setup
    • Troubleshooting
  • Atlantis
    • Atlantis for iOS
  • BASIC FEATURES
    • Proxyman Proxy Helper Tool
    • Request / Response Previewer
    • SSL Proxying
    • Bypass Proxy List
    • Import / Export
    • Content Filter
    • Multiple Tabs
    • Horizontal/Vertical/Window Layout
    • Copy as
    • Custom Previewer Tab
    • Custom Header Column
    • Regex (Regular Expression)
    • Filter JSON Response
    • Highlight by Color and Add Comment
    • Import / Export Settings
    • Multipart Form-Data Previewer
    • JSONPath
    • Customize Toolbar
    • Localization
    • Quick Preview
  • ADVANCED FEATURES
    • Repeat
    • Edit & Repeat
    • Compose new Request
    • No Caching
    • Breakpoint
    • Breakpoint Templates
    • Map Local (File)
    • Map Local (Directory)
    • Map Remote
    • External Proxy
    • Save Session
    • Protobuf
    • WebSocket
    • Clear Session
    • Block List
    • Allow List
    • Charles Proxy Converter
    • Custom Certificates
    • GraphQL
    • Network Conditions
    • Multiple Filters
    • Custom Filters
    • Publish to Gist
    • Reverse Proxy
    • Code Generator
    • Diff
    • Access Control
    • DNS Spoofing
    • SOCKS Proxy
    • Swagger OpenAPI
    • TLS Key Logging
  • Proxyman Windows
    • Install Certificate
    • WSL
  • Scripting
    • Scripting
    • async/await Request
    • Addons
    • Built-in JS Libraries
    • Write your own Addons
    • Snippet Code
    • Environment Variables
  • Troubleshooting
    • Proxyman does not work with VPN apps
    • My Remote Devices (iOS/Android) could not connect to Proxyman?
    • iOS 16 and iOS 17 issues
    • SSL Error from HTTPS Request/Response
    • I could not see any requests from my localhost server
    • I could not see any HTTP traffic from my NodeJS, Python, or Ruby scripts
    • *.local requests do not appear on Proxyman
    • I couldn't see any traffics on Proxyman
    • I couldn't see any requests from 3rd-party network libraries
    • [Breakpoint] Modify Request/Response by Raw Message
    • Could not change Proxyman App Icons
    • Lost data after updating Proxyman app?
    • Proxyman consumes too much RAM & unresponsive
Powered by GitBook
On this page
  • 1. What's it?
  • 2. How to use on macOS?
  • 3. How to use on Windows/Linux?
  • 4. Notes
  1. Scripting

async/await Request

1. What's it?

From Proxyman macOS v3.5.0 and Windows/Linux v2.11.0 or later, you can use async / await to make an HTTP/HTTPS call for retrieving external resources inside your Script.

  • On macOS: Use `$http`

  • On Windows/Linux: Use built-in `axios`

Sample: POST Request with JSON Body (macOS)

async function onResponse(context, url, request, response) {  
  // Define JSON Body and Header
  // Make sure "Content-Type" is "application/json"
  var param = {
    body: {
      "user": {
        "name": "Proxyman"
      }
    },
    headers: {
      "Content-Type": "application/json"
    }
  }

  // POST request with await
  var output = await $http.post("https://httpbin.org/post", param);
  
  // Get Status Code
  console.log(output.statusCode);
  
  // Get body
  console.log(output.body)
  
  // Get header
  console.log(output.headers)
  
  // Done
  return response;
}

2. How to use on macOS?

Method

var output = await $http.get("https://httpbin.org/anything");
var output = await $http.post("https://httpbin.org/anything");
var output = await $http.put("https://httpbin.org/anything");
var output = await $http.update("https://httpbin.org/anything");
var output = await $http.delete("https://httpbin.org/anything");

Output format

var output = await $http.get("https://httpbin.org/anything");
console.log(output)

// print
{
    "statusCode": <Int>,
    "headers": <Object>,
    "body": <Object>
}

Sample Code

3. How to use on Windows/Linux?

For example:

async function getUser() {
  try {
    const response = await axios.get('/user?ID=12345');
    console.log(response);
  } catch (error) {
    console.error(error);
  }
}

4. Notes

  • Make sure you defined the async function on onRequest() and onResponse():

async function onRequest(context, url, request) {
    var output = await $http.get("https://httpbin.org/get");
    return request;
}

async function onResponse(context, url, request, response) {
    var output = await $http.get("https://httpbin.org/get");
    return response;
}
  • Request Timeout is 10 seconds.

  • The inline HTTP Request doesn't go through the Proxyman Proxy, so it isn't affected by other debugging tools.

  • Use can use await $http.get() on both onRequest() and onResponse()

  • Make sure the Body type is matched with the Content-Type header.

JSON Body with application/json

var param = {
    body: {
      "name": "Proxyman",
    },
    headers: {
      "Content-Type": "application/json"
    }
  }

Encoded form Body with application/x-www-form-urlencoded

var param = {
    body: {
      "key1": "value1",
      "key2": "value2"
    },
    headers: {
      "Content-Type": "application/x-www-form-urlencoded"
    }
  }
PreviousScriptingNextAddons

Last updated 1 year ago

Please checkout the for more sample code.

Proxyman Windows/Linux ships with a built-in library, it means we can use the axios syntax to make HTTP(s) requests.

axios
GET Request with Query
POST Request with JSON Body
POST Request with application/x-www-form-urlencoded body
PUT / PATCH / DELETE Request
HTTP Snippet code