send data using http POST from client and receive response from server using netcat over specific port

server :

$ vim 
while true;
        do {
                echo -e 'HTTP/1.1 200 OK\r\n'; sh;
        } | nc -l 8909;
$ vim 
echo "This is response from nc with http OK"
echo "\n"
echo "Cmdline is :"
cat /proc/cmdline
echo "\n"

Now, start listening on socket as,

$ bash 

Now, on client/application side, lets write a curl POST as,

curl -k \
        -H "Content-Type:text/xml; charset=UTF-8" \
        -X POST \
        -d '<?xml version="1.0" encoding="UTF-8"?>
        </address>' http://localhost:8909 -v

Now, start the client as,

$ bash 

And you will get the response as,

$ bash 
Note: Unnecessary use of -X or --request, POST is already inferred.
* Rebuilt URL to: http://localhost:8909/
*   Trying
* Connected to localhost ( port 8909 (#0)
> POST / HTTP/1.1
> Host: localhost:8909
> User-Agent: curl/7.47.0
> Accept: */*
> Content-Type:text/xml; charset=UTF-8
> Content-Length: 181
* upload completely sent off: 181 out of 181 bytes
< HTTP/1.1 200 OK
* no chunk, no close, no size. Assume close to signal end
This is response from nc with http OK
Cmdline is :
BOOT_IMAGE=/boot/vmlinuz-4.4.0-71-generic root=UUID=6dc72f0f-0d95-4e80-8ab7-c2331c79ca08 ro quiet splash vt.handoff=7
* Closing connection 0
Android Android Commands Android Java Applications Application Libraries Application Stack / User Interface Bash / Shell Scripts Commands and Packages Compilation Content Management System - CMS Core Kernel C Programs Development & Build Development Environment Setup Errors & Failures Flutter git Go Language Programs Hardware Platforms HTML JAVA Programs Kernel & Device Drivers Linux, OS Concepts and Networking Linux Device Drivers Linux Host, Ubuntu, SysAdmin Linux Kernel Linux Networking Middleware Libraries, HAL Monetization / Google AdSense Multimedia - Audio, Video, Images NDK / Middleware / HAL OS Concepts PHP Programming Languages RaspberryPi Scripting and Automation Search Engine Optimisation ( SEO ) Social Media Socurce Code Management ( SCM ) System Administration, Security Testing and Debugging Uncategorized User Interface Web design and development Wordpress Yocto / Bitbake / Openembedded

Leave a Reply / Ask Question