I'm using the curl api from http://curl.haxx.se/ in a c++ application. I'm trying to write the equivalent of:
curl -v -X POST -H "Content-type: application/json; charset=utf-16" --data-binary #some data.json
I'm using curl_easy_setopt() to set up the various options but the bit I can't figure out is the --data-binary flag. Which CURLOPT setting would I use to set this?
Thanks in advance
You should use CURLOPT_POSTFIELDS:
specify data to POST to server [...] Pass a char * as parameter, pointing to the full data to send in a HTTP POST operation. You must make sure that the data is formatted the way you want the server to receive it.
Note: you can easily discover this by using the --libcurl option:
--libcurl FILE Dump libcurl equivalent code of this command line
Related
I have been working on uploading a simple XML file to a specialized Web Server. This webserver only supports the use of POST or GET, so it eliminates the use of CURLOPT_UPLOAD which only provides for PUT.
I can use the command line to send the file using the following command line
curl -H 'Content-Type: text/xml; charset=utf-8' -H 'SOAP Action:'
-T igs_meters2.xml -X POST //url//
I tried to use CURLOPT_POST and CURLOPT_READDATA, but received a 413 Request Entity Too Large.
I know this cannot be this hard, but I am out in areas I have never work in. Thanks in advance for an idea.
SOLVED:
the tip about CUSTOMREQUEST was what I needed to find. That helped, and I also needed to add in an HTTPHEADER for CONTENT-TYPE and SOAPAction:
I'm using a curl command to send a large file (100+ MB) to a web service. I'm noticing that only when I send the file to the web service using curl the file gets mangled and data is lost.
Here is the command I'm using to send the file:
curl -v --raw -X POST -H "Transfer-Encoding: chunked" -H "Content-Type: text/xml; charset=UTF-8" -d #medline16n0736.xml "http://localhost:2323/TestWebService"
Am I missing something? I thought telling it to use text/xml and charset=UTF-8 would keep it UTF-8 once received by the web service.
You are asking curl to post the XML file using the -d option, which will post the file as if it were being submitted via an HTTP webform in application/x-www-webform-urlencoded format. To post the file by itself, use the -T option instead. Also, you are using the --raw option, which will disable handling of HTTP transfer encodings, even though you are sending a Transfer-Encoding: chunked header. Remove --raw and -T will detect the header to enable chunking.
You are also asking curl to send a Content-Type header to tell the WebService that the uploaded data is UTF-8 encoded XML. It is your responsibility to make sure the XML file is actually UTF-8 encoded. Curl won't check that for you.
i am very new to the java EE.
I have built some simple restful client for calling rest api's from java using jersey framework.
I have one curl request which i have to call from java
curl -i -X POST 'https://{url}' -H 'Content-Type: application/x-www-form-urlencoded' -H "Accept: application/vnd.newbay.dv-1.8+json" -H "X-HTTP-METHOD-OVERRIDE: DELETE" -H "X-Client-Platform: SERVICES" -H "X-Client-Identifier: IL" --insecure --data 'path=%2FMy+Samsung+GT-I9082%2F20130822_172409.jpg&path=%2FMy+Samsung+GT-I9082%2F20130905_085407.jpg'
Here the paths of file are passed as form post in curl using --data.
Can anyone tell me how to call this api from my java program using jersey framework? I am having difficulty because of this --data part? how exactly i will pass that in my restful java client that i cant understand.
Also can anyone tell me how to pass form post --data part while calling the same api from soapUI?
In your cURL command, --data provides post data in a classic html form format. You shoud alrealy be aware of that because the content-type is explicit : application/x-www-form-urlencoded
Jersey can handle this encoding for you, using MultivaluedMapImpl.
see Sending Name Value Pair in POST using Jersey Client
I'm currently working on a visual studio C++ project that needs to use libcurl to access some apis of my website which uses Django.
I'm using django-tastypie to provide api, and right now I can use this api by using this curl command:
curl --dump-header - -H "Content-Type: application/json" -X PATCH --data '{"body": "This actually is my last post."}' http://localhost:8000/api/v1/entry/4/
to update data on my server. As a test, it works, but what I really need is to write code in C/C++ with libcurl that does the same.
I'm just starting to look at libcurl and not quite sure how to do that. I assume that I should use curl_easy_setopt but I can't find the right options to set.
So my question is
Is it possible to use libcurl to achieve the same goal as that command? I'm not familiar with libcurl.
If so, how to set options like -x PATCH and content-Type? I looked at the document and didn't seem to find how.
Thanks for any help.
As #deltheil suggested, I tried --libcurl.
But notice the code generated isn't quite right in my case. The -H "Content-Type: application/json" part wasn't in the code.
You need to set headers like this
headers = curl_slist_append(headers, "Content-Type: application/json");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
But the option --libcurl is quite helpful.
This post about json requests in C helped me a lot.
I have just started to use Siege to do load/stressing test on a new web server. I am trying to test on my most resource/performance heavy script, but the script requires cookies. What is the proper format for using the --header option in siege?
I have tried this with no luck:
siege --header="Set-Cookie: PHPSESSID=--COOKIE--; iptoken=--COOKIE--" http://www.myurl.com/script.php,
There is no documentation on this that I could find, so any ideas/suggestions would be appreciated.
The answer is to use --header="Cookie: --COOKIE_DATA--" (ref. wiki.wsmoak.net/cgi-bin/wiki.pl?Siege).