I am trying to make a post request using curl. One of the parameters in the end-point i have defined is supposed to be an absolute url that I can copy and paste from the browser. The url will look something like this:
http://myApplication.com/query/query2?parameter1=value1¶meter2=value2#someHash
Now this seems pretty straightforward, so I tried to pass this as a string
-d "url='http://myApplication.com/query/query2?parameter1=value1¶meter2=value2#someHash'" in my curl command, but I am receiving null in the url. Can someone please tell me the correct way to pass this url to my end-point? :\
It probably wants it URL encoded. Try:
curl --data-urlencode "url=[your pasted URL]" [where-to-post]
Related
I can curl a website URL by passing on some header params. I am trying to get the same result on the browser but I cannot build the URL for the browser in the right way.
My curl looks something similar
curl -X GET -u 'xyz#gmail.com' -H "app-key: some-keys" -H "account-email: procurement#gmail.com" -H 'Content-Type: application/json' -d 'paused=false' https://api.pingdom.com/api/2.1/checks
When prompted for the password, i can give the password and Iget the JSON response.
Now I try to build the same URL on my browser. The browser prompts for user name and password which I have already given.
Now my URL looks like this.
https://api.pingdom.com/api/2.1/users?account-email=procurement#gmail.com&app-key=some-key
I get a forbidden (as JSON reponse) when I try from the browser and from Curl I get the proper JSON response.
How can I add header params to a URL when pinging from the browser?
How can I add header params to a URL when pinging from the browser?
That's not possible. Besides it, from the browser address bar you won't be able to use HTTP methods other than GET.
So I advise you to you proper tools to target/test your Web API such as Postman or Paw.
I'm using "curl -L --post302 -request PUT --data-binary #file " to post a file to a redirected address. At the moment the redirection is not optional since it will allow for signed headers and a new destination. The GET version works well. The PUT version under a certain file size threshold works also. I need a way for the PUT to allow itself to be redirected without sending the file on the first request (to the redirectorURL) and then only send the file when the POST is redirected to a new URL. In other words, I don't want to transfer the same file twice. Is this possible? According to the RFC (https://www.rfc-editor.org/rfc/rfc2616#section-8.2) it appears that a server may send a 100 "with an undeclared wait for 100 (Continue) status, applies only to HTTP/1.1 requests without the client asking to send its payload" so what I'm asking for may be thwarted by the server. Is there a way around this with one curl call? If not, two curl calls?
Try curl -L -T file $URL as the more "proper" way to PUT that file. (Often repeated by me: -X and --request should be avoided if possible, they cause misery.)
curl will use "Expect: 100" by itself in this case, but you'll also probably learn that servers widely don't care about supporting that anyway so it'll most likely still end up having to PUT twice...
I thought GET is not supposed to have a body. But in the context of elasticsearch, I keep seeing this kind of query (see here for instance):
curl -XGET localhost:9200/test/_msearch --data-binary #requests; echo
How is the binary data sent in this case? Can somebody explains what is going on and how this works?
I first thought it was converted to a POST but, I put a proxy in front of Elasticsearch and saw that curl was really sending a GET. Though I could find the data neither in the header, nor in the parameter, nor in the body. So it seems like my proxy also got confused by this request.
But when I execute the request directly against elasticsearch, it works just fine. What gives?
GETs with bodies are allowed but not considered to be very "meaningful". You can see this question and answer for a full discussion. HTTP GET with request body
and this answer about your proxy: https://stackoverflow.com/a/978173/3516034
I've tried this every which way, but, I cannot seem to get the syntax right (though I can make it work through a website such as hurl.it). I'm trying a basic HTTP POST request with CURL and I need it to do the following:
1.) Be able to do a very basic non-oauth login (username and password) to http://www.fake.site/create
2.) Send over a few HTTP headers such as "Host, Connection, Content-Length, User-Agent, etc."
3.) Be able to pass over 1 parameter in this format {"guid":"","style":"The Style Here"}
4.) Be able to follow a redirect(s)
I would appreciate any assistance you may have--I have literally been to over 5 pages of Google results and I just hit a snag at ever turn with my CURL code.
Help and Thank you!
curl -X POST -L
-u "auth-User:auth-password"
-d "{\"guid\":\"\",\"style\":\"The Style Here\"}"
-H "Content-Type: application/json"
"http://www.fake.site/create"
You can add more headers through -H parameter if you want.
What would the following cURL command look like as a generic (without cURL) http request?
feedUri="https://www.someservice.com/feeds\
?prettyprint=true"
curl $feedUri --silent \
--header "GData-Version: 2"
For example how could such an http request be expressed in the browser address bar? Partucluarly, how do I express the --header information if I were to just type out the plain http request?
I don't know of any browser that lets you specify header information in the address bar. I believe there are plug-ins that let you do this, but I don't have any experience with them.
Here is one for firefox that looks promising:
https://addons.mozilla.org/en-US/firefox/addon/967
Basically what you want to do is not a standard browser feature.