HTTP test server accepting GET/POST requests

2019-01-03 00:24发布

I need a live test server that accepts my requests for basic information via HTTP GET and also allows me to POST (even if it's really not doing anything). This is entirely for test purposes.

A good example is here. It easily accepts GET requests, but I need one that accepts POST requests as well.

Does anyone know of a server that I can send dummy test messages too?

标签: http post
13条回答
神经病院院长
2楼-- · 2019-01-03 01:00

https://www.mockable.io. It has nice feature of getting endpoints without login (24h temporary account)

查看更多
家丑人穷心不美
3楼-- · 2019-01-03 01:04

Create choose a free web host and put the following code

 <h1>Request Headers</h1>
 <?php
 $headers = apache_request_headers();

 foreach ($headers as $header => $value) {
     echo "<b>$header:</b> $value <br />\n";
 }
 ?>
查看更多
迷人小祖宗
4楼-- · 2019-01-03 01:06

nc one-liner local test server

Setup a local test server in one line under Linux:

nc -kdl localhost 8000

Sample request maker on another shell:

wget http://localhost:8000

then on the first shell you see the request that was made appear:

GET / HTTP/1.1
User-Agent: Wget/1.19.4 (linux-gnu)
Accept: */*
Accept-Encoding: identity
Host: localhost:8000
Connection: Keep-Alive

nc from the netcat-openbsd package is widely available and pre-installed on Ubuntu.

Tested on Ubuntu 18.04.

查看更多
倾城 Initia
5楼-- · 2019-01-03 01:07

I have created an open-source hackable local testing server that you can get running in minutes. You can create new API's, define your own response and hack it in any ways you wish to.

Github Link : https://github.com/prabodhprakash/localTestingServer

查看更多
爱情/是我丢掉的垃圾
6楼-- · 2019-01-03 01:09

http://httpbin.org/

It echoes the data used in your request for any of these types:

查看更多
SAY GOODBYE
7楼-- · 2019-01-03 01:17

If you want a local test server that accepts any URL and just dumps the request to the console, you can use node:

const http = require("http");

const hostname = "0.0.0.0";
const port = 3000;

const server = http.createServer((req, res) => {
  console.log(`\n${req.method} ${req.url}`);
  console.log(req.headers);

  req.on("data", function(chunk) {
    console.log("BODY: " + chunk);
  });

  res.statusCode = 200;
  res.setHeader("Content-Type", "text/plain");
  res.end("Hello World\n");
});

server.listen(port, hostname, () => {
  console.log(`Server running at http://localhost:${port}/`);
});

Save it in a file 'echo.js' and run it as follows:

$ node echo.js
Server running at http://localhost:3000/

You can then submit data:

$ curl -d "[1,2,3]" -XPOST http://localhost:3000/foo/bar

which will be shown in the server's stdout:

POST /foo/bar
{ host: 'localhost:3000',
  'user-agent': 'curl/7.54.1',
  accept: '*/*',
  'content-length': '7',
  'content-type': 'application/x-www-form-urlencoded' }
BODY: [1,2,3]
查看更多
登录 后发表回答