Print HTML Response with localhost cUrl - Linux - linux

I want to execute PHP Script on my Ubuntu Virtual Machine but I only have access to the command line. I've thought about using cUrl but I have a problem with it :
When I use the following command : "curl http://localhost/myscript.php"
The response is the plain file ("<?php echo "<p>Hello world</p>"; ?>") instead of html response ("<p>Hello world</p>")
How to solve this problem ?
Thank you

You may have to set the content-type using header().
Before the echo statement, insert this:
header('Content-Type: text/html');
See: http://php.net/manual/en/function.header.php

Related

Curl request with comma in the directory name in bash

I have problem to execute curl request in the directory has comma in the name using bash command line.
curl --request POST --form "file=#$PWD/input_file" http://HOSTURL.com > output_file
if the directory name is
"test" works
"test test" works
"test, test" doesn't work.
I tried many ways to escape characters like quotations, back slush, changing IFS... but still getting error "failed creating formpost data".
Could someone advise how I should treat such directory names?
This looks like a case curl isn't designed to handle. However, by passing the filename on stdin, you can avoid needing it to correctly parse that value at all.
curl --request POST --form "file=#-" http://HOSTURL.com <input_file >output_file

Curl won't submit form. Why not?

I'm trying to run CURL from the command line, to submit a form. The form is created from php script (see below), that can be accessed via the URL:
http://london.scripts.mit.edu/z.php
I've tried numerous CURL commands from linux, and none of them work. For example:
curl -X POST -F "name=test" https://london.scripts.mit.edu/z.php
I realize that there is some obvious flaw that I'm overlooking, because this feature is so well documented. But it doesn't work for me. Thanks. - Mark
<?php
print "<!DOCTYPE html>";
print "<html><body>";
print "<p>Enter name:</p>";
print "<form action=\"./request_account.php\" method=\"post\" id=\"form\">\n";
print "<input type = \"text\" name = \"name\" id = \"name\"><br />\n";
print "<input type = \"submit\" value = \"Submit\" id = \"submit\">\n";
print "</form></body></html>";
?>
The problem is that curl won't directly execute the action script specified by the html form command. There are workarounds on the web, but I'm going to simply not use a separate action script.

Alert!: Unsupported URL scheme! error when sending bulk sms using lynx

Team kindly help on the error Alert!: Unsupported URL scheme! when snding bulk sms in linux bash script. the lynx command works fine for static URL. This is what i have got below
#!/bin/bash
a="lynx -dump 'http://localhost:13013/cgi-bin/sendsms?from=8005&to="
b="&username=tester&password=foobar&smsc=smsc1&text=Test+mt+update'"
for i in cat numbers.txt;do $a$i$b;echo sent $i; done;
numbers
258909908780
256789123456
676675234789
The problem is the single quote before http:. Quotes are not processed after expanding variables, so it's being sent literally to lynx. There's no 'http URL scheme, hence the error message.
Remove the quotes before http: and after +update.
#!/bin/bash
a="lynx -dump http://localhost:13013/cgi-bin/sendsms?from=8005&to="
b="&username=tester&password=foobar&smsc=smsc1&text=Test+mt+update"
for i in $(cat numbers.txt);do $a$i$b;echo sent $i; done;
For more information about this, see
Setting an argument with bash

How to get this applescript working?

So the goal of this little diversion is to be able to select a piece of text containing a URL and have OS X convert it to a short URL using the goo.gl URL shortener service.
To that end I have created a service using Automator that accepts text input and passes that input to a "Run AppleScript" action. The AppleScript is listed below.
I've installed node.js v0.10.33 and also installed a node package called json (http://trentm.com/json/)
The script below works fine as long as I don't pipe the output to the json node app.
The curl command with piping to the json node app works perfect in Terminal.
My guess is something with the shell environment is off, but I have no idea how to look into that.
Any help?
-- shorten URLs via goo.gl URL shortener
-- syntax derrived from Scott Lowe # blog.scottlowe.org
on run {input, parameters}
set curlCommand to "curl https://www.googleapis.com/urlshortener/v1/url -H 'Content-Type: application/json' -d '{\"longUrl\": \"" & input & "\"}' | /usr/local/bin/json id"
set jsonResult to (do shell script curlCommand)
return jsonResult
end run
A great tool for handling JSON in Applescript is the free App JSON Helper (App Store). It converts JSON to Applescript dictionaries. So my answer is very (very) similar to #regulus6633 post, but without text parsing the JSON:
set input to "http://stackoverflow.com/questions/26757656/how-to-get-this-applescript-working"
-- Note: without piping to grep at the end!
set curlCommand to "curl https://www.googleapis.com/urlshortener/v1/url -H 'Content-Type: application/json' -d '{\"longUrl\": \"" & input & "\"}'"
-- getting the full JSON answer
set jsonResult to do shell script curlCommand
-- using JSON Helper to translate JSON to Applescript dictionary
tell application "JSON Helper"
set shortURL to |id| of (read JSON from jsonResult)
end tell
return shortURL
Greetings, Michael / Hamburg
Why do you have "return curlCommand"? Don't you really want "return jsonResult"?
Admittedly I don't know anything about json but the result of the curl command is a string and I do know how to parse a string in applescript. Here's how I would write your code parsing it as a string. Note I used this webpage's url as "input"...
set input to "http://stackoverflow.com/questions/26757656/how-to-get-this-applescript-working"
set curlCommand to "curl https://www.googleapis.com/urlshortener/v1/url -H 'Content-Type: application/json' -d '{\"longUrl\": \"" & input & "\"}' | grep '\"id\"'"
set jsonResult to do shell script curlCommand
set shortURL to text 9 thru -2 of jsonResult
return shortURL

Invoke Curl from within shell script

I've below code in shell script
#!/bin/bash
oauth_consumer_key='sdfsfsd'
oauth_consumer_key_secret='1sdfsdfs1'
oauth_token='5wrwerwr476a1737fe09de2e4ew'
oauth_token_secret='ec2231779e4'
url='https url goes here'
token=$(./oauth $oauth_consumer_key $oauth_consumer_key_secret $oauth_token $oauth_token_secret GET $url)
curl_path='/usr/bin/curl'
curl_args="-H 'Authorization: $token'"
resp=$($curl_path $curl_args $url)
echo $resp
Here, I'm first running oauth.sh from this program by passing params & capturing output in token which works as expected. And this output looks as shown below:
OAuth oauth_consumer_key="45435", oauth_token="4r43", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1415328827", oauth_nonce="4535345", oauth_version="1.0", oauth_signature="bKeewO%2BTJ7IHjurhtaftn9dNfxA%3D"' 'my url goes here'
Now, I need to invoke curl command from this program by passing above as param as shown below:
curl -H 'Authorization: OAuth oauth_consumer_key="45435", oauth_token="4r43", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1415328827", oauth_nonce="4535345", oauth_version="1.0", oauth_signature="bKeewO%2BTJ7IHjurhtaftn9dNfxA%3D"' 'my url goes here'
When I run above curl command from terminal console, it works but from my shell script it gives error couldn't resolve OAuth
Can anyone help me out in fixing this issue?
Thanks!
It looks like this line is looking for "oauth" in the current directory.
token=$(./oauth
I would try putting the absolute path to oauth instead of ./oauth and see if that works.
If that doesn't work, I would strip it down a little and comment out everything after that line and just echo $token and see if it's showing the expected results and go from there.

Resources