form_post - Linux


Overview

form_post is a versatile command-line tool designed to facilitate the sending of POST requests with multipart data to web servers. It excels in automating the process of uploading files, submitting forms, and interacting with APIs that require complex request bodies.

Syntax

form_post [options] <url> -f <file> -d <key=value>...

Options/Flags

  • -f <file>: Path to the file to be uploaded. Multiple files can be specified by repeating this option.
  • -d <key=value>: Data pairs to include in the POST request body. Multiple key-value pairs can be supplied.
  • -H <header>: Custom HTTP headers to set in the request. Can be used multiple times.
  • -u <username:password>: HTTP Basic Authentication credentials.
  • -k: Disable SSL/TLS certificate verification.
  • -v: Enable verbose output for debugging.
  • -h: Display help information.

Examples

Upload a File:

form_post https://example.com/upload -f my_file.txt

Submit a Form:

form_post https://example.com/form -d name=John -d email=john@example.com

Send Custom Headers:

form_post https://example.com/api -H "Content-Type: application/json" -H "Authorization: Bearer 123"

Common Issues

  • Permission Denied: Ensure that the file to be uploaded has the necessary read permissions.
  • Connection Timeout: Increase the connection timeout using the --connect-timeout option.
  • SSL Certificate Verification Error: Use the -k option to disable certificate verification if the server’s certificate is self-signed or invalid.

Integration

Combining with Other Commands:

curl https://example.com/api \
  --data "`form_post -d key=value | base64`"

Using with Scripts:

#!/bin/bash

# Read data from a file
form_post https://example.com/upload -f "$1" \
  | while read line; do
      echo "$line" >> log.txt
  done

Related Commands

  • curl: General-purpose HTTP client
  • httpie: Interactive HTTP client
  • postman: GUI-based HTTP client