8

I have ARM cpu based BusyBox v1.8.1 (Embedded Linux) with limited binaries. How can I http post or put without using curl? I have wget available:

# wget
BusyBox v1.8.1 (2015-04-06 16:22:12 IDT) multi-call binary

Usage: wget [-c|--continue] [-s|--spider] [-q|--quiet] [-O|--output-document file]
        [--header 'header: value'] [-Y|--proxy on/off] [-P DIR]
        [-U|--user-agent agent] url

Retrieve files via HTTP or FTP

Options:
        -s      Spider mode - only check file existence
        -c      Continue retrieval of aborted transfer
        -q      Quiet
        -P      Set directory prefix to DIR
        -O      Save to filename ('-' for stdout)
        -U      Adjust 'User-Agent' field
        -Y      Use proxy ('on' or 'off')

CPU info...

# cat /proc/cpuinfo
Processor       : ARM926EJ-S rev 1 (v5l)
1
  • --post-data= or --post-file= is what you are looking for, the thing is that since that wget is part of the Busybox I don't know if it has all the capabilities or it is a simplified wget and doesn't allow that.
    – YoMismo
    Commented Oct 5, 2015 at 18:46

2 Answers 2

22

A lot depends on what you have in your busybox and other commands. I don't think your limited wget can be used; however, a simple POST request can be emulated with just a cat, provided you can open a socket, e.g. with nc (netcat, socat), telnet, or even with a full version of bash, as it can do a connect, as shown below:

On another machine, use curl to do the request, and copy all the data it writes. Eg:

curl --trace-ascii - -0 -d var=val http://localhost/~meuh/dump.cgi

This shows in the curl trace output that it sent:

POST /~meuh/dump.cgi HTTP/1.0
User-Agent: curl/7.37.0
Host: localhost
Accept: */*
Content-Length: 7
Content-Type: application/x-www-form-urlencoded

var=val

If you put this in a file, you can reproduce the POST, e.g. to google with the bash script:

#!/bin/bash
exec 5<>/dev/tcp/www.google.com/80
cat mypostfile >&5
cat <&5 # reply

This probably only works well for smallish data, and servers that aren't too fussy with \r\n line endings, but may suffice for you.

5
  • Fantastic, what is that '5' in bash script ?
    – irom
    Commented Oct 5, 2015 at 19:19
  • 2
    it's just a new file descriptor. I could have re-used the usual 1 for stdout, but it's better to open the tcp port for input and output (<>) into a new fd, so we can be explicit when doing i/o with the socket.
    – meuh
    Commented Oct 5, 2015 at 19:23
  • brilliantly done
    – robert
    Commented Mar 12, 2016 at 1:33
  • how to make a get? Commented Feb 17, 2017 at 13:20
  • 1
    @KamilDziedzic You should probably post a new question specific to your needs, but if you follow the same technique you end up with a file where the word POST is replaced by GET, and you only need the first 4 lines followed by a blank line (i.e. no Content-Length, no Content-Type, no var=val).
    – meuh
    Commented Feb 17, 2017 at 18:42
1

Many tools can be statically compiled (I know it for sure with netcat) inside Buildroot (http://buildroot.uclibc.org/) and then downloaded using wget onto the device. That's what I did in a similar situation.

Just care to set the correct options, you can access them using make menuconfig. The following option pages will probably be the most important ones for you (I marked the often important options using with !>):

  • Target
  │ ┌────────────────────────────────────────────────────────────────────────────┐ │  
!>│ │        Target Architecture (FOOBAR)  --->                                  │ │  
  │ │        Target Binary Format (ELF)  --->                                    │ │  
!>│ │        Target Architecture Variant (Gen42)  --->                           │ │  
  │ │        Target ABI (EABI)  --->                                             │ │  
  │ │        Floating point strategy (Soft float)  --->                          │ │  
  │ │                                                                            │ │  
  • Build Options
!>│ │        libraries (static only)  --->                                       │ │  
  │ │    ($(CONFIG_DIR)/local.mk) location of a package override file            │ │  
  │ │    ()  global patch directories                                            │ │  
  │ │        Advanced  --->                                                      │ │  
  │ └────────────────────────────────────────────────────────────────────────────┘ 
  • Toolchain
  │ ┌────────────────────────────────────────────────────────────────────────────┐ │  
  │ │        Toolchain type (Buildroot toolchain)  --->                          │ │  
  │ │    (buildroot) custom toolchain vendor name                                │ │  
  │ │        *** Kernel Header Options ***                                       │ │  
!>│ │        Kernel Headers (Manually specified Linux version)  --->             │ │  
!>│ │    (2.6.99) linux version                                                  │ │  
!>│ │        Custom kernel headers series (2.6.x)  --->                          │ │  
  │ │        C library (uClibc)  --->                                            │ │  
  │ │        *** uClibc Options ***                                              │ │  
!>│ │        uClibc C library Version (uClibc 0.9.33.x)  --->                    │ │  

Then build the toolchain using make toolchain and then what tool you need, e.g. make nc.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .