How to set the --compressed curl command option using curl_easy? - libcurl

When I run curl --help I see the following option available:
--compressed Request compressed response (using deflate or gzip)
However, when I visit the documentation on curl_easy's setopt command, I don't see an option to pass in this compressed flag.
How can I set --compressed using curl_easy_setopt please?

--compressed is equivalent to CURLOPT_ACCEPT_ENCODING.

Related

gcurl: command not found in Google Cloud Shell

In Google Cloud Shell, I would like to see a list of enabled service,
When I put the following command
gcurl "https://serviceusage.googleapis.com/v1/proj
ects/myProjectId/services?filter=state:ENABLED"
Then I got this error.
-bash: gcurl: command not found
How to install gcurl?
gcurl is an alias for regular curl plus some headers:
alias gcurl='curl -H "$(oauth2l header --json ~/credentials.json cloud-platform userinfo.email)" -H "Content-Type: application/json"'
Please see here for more details.

wso2 mutual ssl curl command APIM 3.2.0

I tried setup ALLINONE in my local, followed the documentation https://apim.docs.wso2.com/en/latest/learn/api-security/api-authentication/secure-apis-using-mutual-ssl/
it worked, but what will be the curl command for request because the document talks about testing only through postman
You can use the following curl commands when you want to use the header-based approach.
curl -X GET -H "X-WSO2-CLIENT-CERTIFICATE: (Base64 encoded public cert)" "https://localhost:8243/mock/v1" -v
curl -X GET -H "X-WSO2-CLIENT-CERTIFICATE: (Base64 encoded public cert)" "http://localhost:8280/mock/v1" -v
In order to work this, you need to add the following configuration to the deployment.toml in wso2am-3.2.0/repository/conf location.
[apimgt.mutual_ssl]
enable_client_validation = false
You can use the following curl commands if you are using the cert and key.
curl -k --cert int.ext.wso2.com.crt --key int.ext.wso2.com.key -X GET "https://localhost:8243/mock/v1" -v

how to use rest api with curl and c++ in xcode

I'm trying to POST the simple data to the Parse server using REST, but not able to do so, here is the code
#include<curl/curl.h>
curl -X POST \
-H "X-Parse-Application-Id: xxxxxxxxxx" \
-H "X-Parse-REST-API-Key: xxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{"score":1337,"playerName":"Sean Plott","cheatMode":false}' \
https://api.parse.com/1/classes/GameScore
what is X here? do we need to define x? what connection settings need to be used to post the data successfully? and where is the return object is Json, where is is stored?
thanks.
You are trying to use a terminal command in C++, this won't work. X is a command line option for curl.
Below is a basic example of an HTTP POST request submitted with Curl using C. You should be able to adapt this to your needs.
http://curl.haxx.se/libcurl/c/http-post.html

How to test web service using command line curl

I am building a web service for a web application, and I would like a simple tool to test this as I am developing. I have tried some firefox plug-ins (Poster, 'REST Client'), and even though these work fine I have been unable to upload files with them.
Also, I would rather have a command-line tool that I can use to easily write a set of integration tests for this web service and that I can send to consumers of this web service as an example.
I know that curl can work for this but would like a few examples, especially around authentication (using HTTP Basic) and file uploads.
Answering my own question.
curl -X GET --basic --user username:password \
https://www.example.com/mobile/resource
curl -X DELETE --basic --user username:password \
https://www.example.com/mobile/resource
curl -X PUT --basic --user username:password -d 'param1_name=param1_value' \
-d 'param2_name=param2_value' https://www.example.com/mobile/resource
POSTing a file and additional parameter
curl -X POST -F 'param_name=#/filepath/filename' \
-F 'extra_param_name=extra_param_value' --basic --user username:password \
https://www.example.com/mobile/resource
In addition to existing answers it is often desired to format the REST output (typically JSON and XML lacks indentation). Try this:
$ curl https://api.twitter.com/1/help/configuration.xml | xmllint --format -
$ curl https://api.twitter.com/1/help/configuration.json | python -mjson.tool
Tested on Ubuntu 11.0.4/11.10.
Another issue is the desired content type. Twitter uses .xml/.json extension, but more idiomatic REST would require Accept header:
$ curl -H "Accept: application/json"
From the documentation on http://curl.haxx.se/docs/httpscripting.html :
HTTP Authentication
curl --user name:password http://www.example.com
Put a file to a HTTP server with curl:
curl --upload-file uploadfile http://www.example.com/receive.cgi
Send post data with curl:
curl --data "birthyear=1905&press=%20OK%20" http://www.example.com/when.cgi

Curl command line for consuming webServices?

Do you guys know how I can use the Curl command line to POST SOAP to test a web service?
I have a file (soap.xml) which has all the soap message attached to it I just don't seem to be able to properly post it.
Thanks!
Posting a string:
curl -d "String to post" "http://www.example.com/target"
Posting the contents of a file:
curl -d #soap.xml "http://www.example.com/target"
For a SOAP 1.2 Webservice, I normally use
curl --header "content-type: application/soap+xml" --data #filetopost.xml http://domain/path
Wrong.
That doesn't work for me.
For me this one works:
curl
-H 'SOAPACTION: "urn:samsung.com:service:MainTVAgent2:1#CheckPIN"'
-X POST
-H 'Content-type: text/xml'
-d #/tmp/pinrequest.xml
192.168.1.5:52235/MainTVServer2/control/MainTVAgent2
curl -H "Content-Type: text/xml; charset=utf-8" \
-H "SOAPAction:" \
-d #soap.txt -X POST http://someurl
If you want a fluffier interface than the terminal, http://hurl.it/ is awesome.