Curl won't submit form. Why not? - linux

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.

Related

Problem running bitbucket rest api command using python

I,am building a script to update files on Bitbucket using the rest api.
My problems are:
Running the command using subprocess lib and running the command directly on the command line gives two different results.
If I run the command using the command line, when I inspect my commits on the Bit bucket app I can see a Commit message and a Issue.
If I run the command using the help of the subprocess lib I don't have a commit message and a Issue in the end. The commit message sets itself by default to "edited by bitbucket" and the issue is null.
This is the command:
curl -X PUT -u user:pass -F content=#conanfile_3_f62hu.py -F 'message= test 4' -F branch=develop -F sourceCommitId={} bitbucket_URL".format(latest_commit)
The other problem is that I need to pass a file to the content in order to update it.
If I pass it like above it works. The problem is that I am generating the file content as raw string and creating a temporary file with that content.
And when I pass the file as a variable, it does not get the content of the file.
My code:
content = b'some content'
current_dir = os.getcwd()
temp_file=tempfile.NamedTemporaryFile(suffix=".py",prefix="conanfile", dir=current_dir)
temp_file.name = temp_file.name.split("\\")
temp_file.name = [x for x in temp_file.name if x.startswith("conanfile")][0]
temp_file.name = "#" + temp_file.name
temp_file.write(content)
temp_file.seek(0)
update_file_url = "curl -X PUT -u user:pass -F content={} -F 'message=test 4' -F branch=develop -F sourceCommitId={} bitbucket_url".format(temp_file.name, latest_commit)
subprocess.run(update_file_url)
Basically I'am passing the file like before, just passing the name to the content, but it does not work.
If I print the command everything looks good, so I don't know why the commit message does not get set and the file content as well.
Updated:
I was able to pass the file, My mistake was that I was not passing it like temp_file.name.
But I could not solve the problem of the message.
What I found is that the message will only take the first word. If there is a space and one more word after, it will ignore it.
The space is causing some problem.
I found the solution, if someone found himself with this problem we need to use a \ before the message= .
Example: '-F message=\" Updated with latest dependencies"'

Print HTML Response with localhost cUrl - 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

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

Usage of Wget for a long URL

I am trying to download a file with the below URL:
wget http://example.com/reports/downloadreport?roleId=8&loginName=9011613&code=123
But it takes only till
http://example.com/reports/downloadreport?roleId=8
not sending the remaining things. I need to send at least role ID and loginName to get the file.
I tried to create a shell script like below, but that is not working either:
i="http://euroams.eurekaforbes.co.in:8080/efms/reports/bamsinvoiceresultdownload?roleId=8&loginName=9011613"
wget --tries=45 -i $i
How can I fix this?
Enclose the URL in quotes. Your shell is interpreting the "&" rather than passing it as a parameter, so it's seeing what you typed as the following (three commands rather than one):
wget http://example.com/reports/downloadreport?roleId=8 &
loginName=9011613 &
code=123

Curl Complex With Bash

Small Note: I removed the http:// from infront each link, because stackoverflow isn't allowing me to post it in original way.
I wrote a script which access to a webpage, to catch a URL and download it. One of the urls makes curl stop working and the whole URLS in the list to the same.
The script works as following:-
PAGE=$(curl -sL pageurl)
FILE_URL=$(echo $PAGE | sed -e 's/^.*<a href=\"\(.*\)\">\(.*\) alt="File" \/><\/a>.*$/\1/')
The FILE_URL VALUE is
URL/files/PartOne - Booke (Coll).pdf
webprod25.megashares.com/index.php?d01=3109985&lccdl=9e8e091ef33dd103&d01go=1&fln=/adobe reader exe.rar
AND SO One for others
When curl tried to catch this url it shows the following error using the debug mode of bash
++ curl -sOL 'webprod37.megashares.com/index.php?d01=3109985&lccdl=9e8e091ef33dd103&d01go=1&fln=/adobe' reader exe.rar fileshare273.depositfiles.com/auth-13023763920cd7ec18a0fdbfa8b62d35-188.165.197.50-43792102-7713641/FS273-7/PageMaker.rar -sOLJg fileshare601.depositfiles.com/auth-1302376689013d421df6c01e7f64c8d2-188.165.197.50-43801594-82379659/FS601-2/Adobe_Flash_Player_v10.3.180.65.2.rar -sOLJg 'webprod37.megashares.com/index.php?d01=de48789&lccdl=9e8e091ef33dd103&d01go=1&fln=/KAZAMIZA.COM.Adobe.Flash' Player-10.3.180.65.Beta-2.JUDGMENT DAY.rar bellatrix.oron.com/spzsttzwytpflwd76j3ne2moukomuhcdxg6llddfztqa2ztd7cplwwp457h3mxuacq3pbxzs/An-Beat - Mentally Insine '(Original' 'Mix).mp3'
curl: option -: is unknown
curl: try 'curl --help' or 'curl --manual' for more information
The quote marks the curl put it itself, I tried to do some workarounds like escaping url but it not works.
The basic problem seems to be that you are using $() expansion for something that looks to me like a multi line value. You should try iterating over each line.
The other problem looks like one of improper quoting of URLs containing spaces. There's a lone dash (-) in "An-Beat - Mentally Insine"
Oh, one more problem: The sed part to catch the href="..." contents only works if there's exactly one href on the line. If there are two or more, your \(.*\) will match everything else up to the last href. You should use something like href="\([^"]*\)", matching "any number of non-doublequotes followed by a doublequote".
Quote your variables as in:
pageurl='the url'
PAGE=$(curl -sL "$pageurl")
FILE_URL=$(echo "$PAGE" | sed -e 's/^.*<a href=\"\(.*\)\">\(.*\) alt="File" \/><\/a>.*$/\1/')
Otherwise, shell expansion will occur. The error "option -: is unknown" comes from the final part:
An-Beat - Mentally Insine
Because you didn't apply quotes to it, it got parsed as arguments, which you can clearly see in the syntax-highlighted code.

Resources