I've encountering an issue where the endpoint server is returning a '417 Expectation Failed' error after 1024kb has been sent. I don't believe curl is rewriting the headers appropriately before the request is sent to the endpoint. I am using the -H flag and been reading over many different threads, to include the curl manpages, in an attempt to understand what I may be doing wrong.
I'm writing in Perl. Here is how I am setting my headers.
my $curlpath = "/usr/local/bin/curl";
my $xml = #-- yes, xml is really passed but i omitted it
push #curl_vars, "-H 'Content-Type: text/xml; Expect:'"; #-- header flag
push #curl_vars, "-v"; #-- verbose mode
push #curl_vars, "-d"; #-- data flag
push #curl_vars, $xml; #-- data
push #curl_vars, $endpoint;
eval
{
#-- command line execution
open (FILE, "-|") || exec $curlpath, #curl_vars;
$response = join '', <FILE>;
close (FILE);
};
Here is the trimmed curl response from the log.
[Fri Oct 10 16:04:36 2014] > Host: myhost.com\r
[Fri Oct 10 16:04:36 2014] > Accept: */*\r
[Fri Oct 10 16:04:36 2014] > 'Content-Type: text/xml; Expect:'\r
[Fri Oct 10 16:04:36 2014] > Content-Length: 1069\r
[Fri Oct 10 16:04:36 2014] > Content-Type: application/x-www-form-urlencoded\r
[Fri Oct 10 16:04:36 2014] > Expect: 100-continue\r
[Fri Oct 10 16:04:36 2014] > \r
[Fri Oct 10 16:04:36 2014] * HTTP 1.0, assume close after body
[Fri Oct 10 16:04:36 2014] < HTTP/1.0 417 Expectation Failed\r
[Fri Oct 10 16:04:36 2014] < Connection: close\r
[Fri Oct 10 16:04:36 2014] < Content-Length: 18\r
[Fri Oct 10 16:04:36 2014] < \r
You want to change one header and remove another one, so invoke curl with two -H uses:
-H 'Content-Type: text/xml' -H 'Expect:'
That is, each -H changes a single header so you need one -H for every header you want to modify.
Combined with the error ikegami pointed out, that means you'd need
push #curl_vars, '-H', 'Content-Type: text/xml';
push #curl_vars, '-H', 'Expect:';
When you say
curl -H 'Content-Type: text/xml; Expect:'
you call curl with two arguments.
-H
Content-Type: text/xml; Expect:
In your Perl code, however, you pass single argument.
-H 'Content-Type: text/xml; Expect:'
Perhaps you need
push #curl_vars, '-H', 'Content-Type: text/xml; Expect:';
There could be other problems.
Related
I would like to find a PowerShell alternative to curl most specific when calling jenkins api and getting a return output.
curl --silent -k https://jenkins:8443/job/myjob/buildwithParameters -i
The curl parameter -i will return the queue number in the output.
With the queue item I can easily query again the API and get the results of the specific job.
Location: https://jenkinsserver:8443/queue/item/317/
I can successfully wrap curl into a PowerShell script/function however I would like to eliminate this dependency.
PS C:\> curl.exe --silent -k https://jenkinsserver:8443/job/MyJOB/buildWithParameters --user myuser:****myapitoken****** --data ComputerName=XYZ003 --data State=start --data --data ve
rbosity=high -i
HTTP/1.1 201 Created
Date: Wed, 02 Dec 2020 02:52:01 GMT
X-Content-Type-Options: nosniff
Location: https://jenkinsserver:8443/queue/item/317/
Content-Length: 0
Server: Jetty(9.4.30.v20200611)
PS C:\>
gsutil rsync -C "continue" option is not working from backup_script:
$GSUTIL rsync -c -C -e -r -x $EXCLUDES $SOURCE/Documents/ $DESTINATION/Documents/
From systemd log:
$ journalctl --since 12:00
Jul 25 12:00:14 localhost.localdomain CROND[9694]: (wolfv) CMDOUT (CommandException: Error opening file "file:///home/wolfv/Documents/PC_maintenance/backup_systems/gsutil/ssmtp.conf": .)
Jul 25 12:00:14 localhost.localdomain CROND[9694]: (wolfv) CMDOUT (Caught ^C - exiting)
Jul 25 12:00:14 localhost.localdomain CROND[9694]: (wolfv) CMDOUT (Caught ^C - exiting)
Jul 25 12:00:14 localhost.localdomain CROND[9694]: (wolfv) CMDOUT (Caught ^C - exiting)
Jul 25 12:00:14 localhost.localdomain CROND[9694]: (wolfv) CMDOUT (Caught ^C - exiting)
because owner is root rather than user:
$ ls -l ssmtp.conf
-rw-r-----. 1 root root 1483 Jul 24 21:30 ssmtp.conf
rsyc worked fine after deleting the root-owned file.
This happened on a Fedora22 machine, when cron called backup_script which called gsutil rsync.
Thanks for reporting that problem. We'll get a fix for this bug in gsutil release 4.14.
Mike
Here is my request:
> curl -i -H "Accept: application/json" -H "Content-Type:
> application/json" -X GET
> http://access.alchemyapi.com/calls/image/ImageGetRankedImageKeywords?apikey=<key>&image=file%3A%2F%2Ftmp%2Fimage.jpg&imagePostMode=not-raw&outputMode=json
Following http://www.alchemyapi.com/api/image-tagging/image.html
Response:
HTTP/1.1 200 OK Server: nginx Date: Wed, 13 May 2015 04:27:56 GMT
Content-Type: application/xml; charset=utf-8 Content-Length: 440
Connection: keep-alive Cache-Control: no-cache
X-AlchemyAPI-CurrentVersion: 12.15 X-AlchemyAPI-Error-Msg:
content-is-empty X-AlchemyAPI-Key: X-AlchemyAPI-Params:
sentiment=0&knowledgeGraph=0&detectedLanguage=unknown&submitLanguage=detect
X-AlchemyAPI-Status: ERROR X-AlchemyAPI-Total-Transactions: 4
Access-Control-Allow-Origin: *
ERROR
content-is-empty
By accessing AlchemyAPI or using information generated by AlchemyAPI, you are agreeing to be bound by the AlchemyAPI Terms of
Use: http://www.alchemyapi.com/company/terms.html
4
Why?
The image exists:
$ ls -l /tmp/trash1.jpg
-rw-r-----# 1 xx staff 47846 May 12 15:49 /tmp/image.jpg
$
Their support helped me.
Essentially i need to POST the image directly.
Can't use the "image" parameter and filling it with the name of the local file. That parameter actually needs to contain the contents of the image file instead. So instead need to use imagePostMode=raw, and just add the file as the post body, which I would recommend. Something like this:
wget -qO- --post-file YOUR_IMAGE.png "http://access.alchemyapi.com/calls/image/ImageGetRankedImageKeywords?apikey=API_KEY&imagePostMode=raw"
There's plenty of info on how to prevent curl from showing header information when doing a request for the PHP version, but seemingly nothing for the CLI version.
my request is in the form
curl -i -X POST -H 'Content-Type: application/json; charset=UTF-8' -H 'X-Accept: application/json' -H '-d '{"somedata":"12ihiuhihihed994f63dbef6b012b"}' https://myurl.com/v3/oauth/request
Which works, but returns this:
HTTP/1.1 200 OK
Cache-Control: private
Content-Type: application/json
Date: Wed, 27 Mar 2013 20:42:11 GMT
P3P: policyref="/w3c/p3p.xml", CP="ALL CURa ADMa DEVa OUR IND UNI COM NAV INT STA PRE"
Server: Apache/2.2.23 (Amazon)
Status: 200 OK
X-Powered-By: PHP/5.3.20
Content-Length: 54
Connection: keep-alive
{"code":"jkhjhhjhaa","state":null}
when all I really want is this:
{"code":"jkhjhhjhaa","state":null}
Simply remove the -i switch from your curl command.
man curl
said :
-i, --include
(HTTP) Include the HTTP-header in the output. The HTTP-header includes things like server-name, date of the document, HTTP-version and more...
In order to suppress output from CURL CLI --silent option can be used. It perfectly works when curl output is piped as well.
-s, --silent Silent mode (don't output anything)
In case this isn't obvious, also don't use the -v (verbose) switch with -s (silent)
First I'm pretty sure the riak is setting ok by using the command: riak-admin status
But I can't PUT in into a bucket test:
curl -v -X PUT -d 'This is really cool' -H "Content-Type: text/plain" http://markson.hk:8098/buckets/test/1234
< HTTP/1.1 404 Object Not Found
< Server: MochiWeb/1.1 WebMachine/1.9.0 (participate in the frantic)
< Date: Fri, 18 Nov 2011 12:13:03 GMT
< Content-Type: text/html
< Content-Length: 193
Does the error due to the new bucket test? Should I create it first?
Take a look at Basic Riak API Operations, the basic PUT request looks like this:
PUT /riak/bucket/key
Hence your curl example should be similar to:
curl -v -X PUT -d 'The is so cool' -H "Content-Type: text/plain" http://markson.hk:8098/riak/test/1234
But then again, seems like somebody already deposited a test key for you: