如何在不使用 CURL 的情况下运行 HTTP 请求

iro*_*rom 2 wget busybox

我有基于 ARM cpu 的 BusyBox v1.8.1(嵌入式 Linux),二进制文件有限。如何在不使用 curl 的情况下 http 发布或放置?我有可用的 wget:

# 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')
Run Code Online (Sandbox Code Playgroud)

CPU信息...

# cat /proc/cpuinfo
Processor       : ARM926EJ-S rev 1 (v5l)
Run Code Online (Sandbox Code Playgroud)

meu*_*euh 12

很大程度上取决于您在busybox 和其他命令中的内容。我认为你的limitwget不能用;然而,一个简单的POST 请求可以只用一个 来模拟cat,前提是你可以打开一个套接字,例如使用nc (netcat, socat) telnet, 或者甚至使用完整版本的bash,因为它可以进行连接,如下所示:

在另一台机器上,用于curl执行请求,并复制它写入的所有数据。例如:

curl --trace-ascii - -0 -d var=val http://localhost/~meuh/dump.cgi
Run Code Online (Sandbox Code Playgroud)

这显示在它发送的 curl 跟踪输出中:

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
Run Code Online (Sandbox Code Playgroud)

如果你把它放在一个文件中,你可以重现 POST,例如使用 bash 脚本到谷歌:

#!/bin/bash
exec 5<>/dev/tcp/www.google.com/80
cat mypostfile >&5
cat <&5 # reply
Run Code Online (Sandbox Code Playgroud)

这可能只适用于较小的数据,以及对\r\n行尾不太挑剔的服务器,但可能对你来说就足够了。

  • 它只是一个新的文件描述符。我可以重新使用通常的 1 作为 stdout,但最好打开用于输入和输出 (&lt;&gt;) 的 tcp 端口到新的 fd,这样我们在使用套接字进行 I/O 时就可以明确。 (2认同)