0

I have url (www.blabla.web.id/proses_data.php) online. And I want to submit data to that url from my bash script. I'm using ash, bash inside OpenWRT.

I'm trying this technique,

#!/bin/sh
elinks -dump http://www.blabla.web.id/proses_data.php?data=thisisthedata

But it use GET method. How to use POST method?

Jenz
  • 8,280
  • 7
  • 44
  • 77
rezafahlevi08
  • 347
  • 1
  • 5
  • 10

1 Answers1

2

elinks is a program for browsing the web in text mode. you may not post data throgh it.

but Linux provide beautiful tools for POST data

with this nice and little command

curl --data "param1=value1&param2=value2" http://hostname/resource

Also POST if web response in JSON then

curl -X POST  -H "Accept: Application/json" -H "Content-Type: application/json" http://someHostName/someEndpoint -d '{"id":"IDVALUE","name":"Mike"}' | grep }| python -mjson.tool

Aslo some little trick here

Add this function in php script

function getInput() {
  $fr = fopen("php://stdin", "r");
  while (!feof ($fr)) {
    $input .= fgets($fr);
  }
  fclose($fr);
  return $input;
}

$takethis = getInput();

Now in bash do like

echo 22333333 | php my.php
Jayesh Bhoi
  • 24,694
  • 15
  • 58
  • 73