the following code snippet doesn't make sense to me.
curl -XGET 'localhost:9200/bank/_search?pretty' -H 'Content-Type: application/json' -d'
{
"query": { "match_phrase": { "address": "mill lane" } }
}
'
Does HTTP GET contain a body (data)?
No, GET takes only a QUERY_STRING, but no data.
Usually data are sent via POST or PUT HTTP verbs
Check http://www.restapitutorial.com/lessons/httpmethods.html
I found the answer here! In the ElasticSearch Docs.
https://www.elastic.co/guide/en/elasticsearch/guide/current/_empty_search.html
The HTTP libraries of certain languages (notably JavaScript) don’t allow GET requests to have a request body. In fact, some users are surprised that GET requests are ever allowed to have a body.
...
Related
I tried to get an access token with the google documentation.
curl -L -X POST 'https://www.googleapis.com/oauth2/v4/token?
client_id=oauth2-client-id& client_secret=oauth2-client-secret&
code=authorization-code& grant_type=authorization_code&
redirect_uri=https://www.google.com'
With this request it didn't worked.
I added -H 'Content-Length: 0' and now I'm ending up with
{
"error": "invalid_grant",
"error_description": "Bad Request"
}
Anybody have an idea?
If fixing the space didn't work, re-do you linking here from the Google guide, steps 1-6. Then get a new authorization code. I had the same issue and re-linking worked for me (with the -H flag).
it seems you have a space in the request:
/v4/token? client_id=oauth2-client-id
when i tried to copy past the commands from the documentation it didn't work.
i had to re-edit the request before i could use it and it worked.
I've got the same issue.
curl -L -X POST "https://www.googleapis.com/oauth2/v4/token?client_id=<client_id>.apps.googleusercontent.com&client_secret=<secret>&code=4/4wGANiKF5......N0Jg&grant_type=authorization_code&redirect_uri=https://www.google.com"
Stumped
Don't you have to use a different redirect_uri? Your own configured redirect uri?
I'm doing a coding exercise developing a HTTP server using Go's net/http library. The server is supposed to pass a series of tests in a Gitlab pipeline. I have no access to these tests and I can't see how they are implemented.
The problem is that one test for an expected HTTP 204 No Content response fails as follows:
Expected an empty response body "", got "\n"
The way I build the response in my code is:
// w is the http.ResponseWriter of the handler function.
w.WriteHeader(http.StatusNoContent)
w.Header().Del("Content-Type")
w.Write(nil)
I also tried w.Write(make([]byte, 0)) with the same result.
I'm testing it locally with curl but I can't really see the characters that are being returned in the body:
$ curl -i --header "Content-Type: application/x-www-form-urlencoded" --request POST --data "PARAMETER=1" host:9000/path
HTTP/1.1 204 No Content
Date: Thu, 10 Sep 2020 16:12:21 GMT
$
Is the net/http server actually returning a carriage return, and how can I prevent this?. Thank you.
Sorry, I was looking at the wrong piece of code. Because I don't have any details about the tests, I don't really know what exact case is being tested. The comments above are correct, just using w.WriteHeader(http.StatusNoContent) doesn't produce any carriage return in the body. No need to delete Content-Type. My mistake was that I was using http.Error(w, "", http.StatusNoContent) instead.
I am using R.
I am new to API's and trying to figure out how to put the post call together to get the required bearer token.
I am using the Experian Sandbox.
Once I have the bearer token i'm good but getting the Post call put together is proving to be very difficult for me.
+below was clipped from the developer portal.
The call to get the Oauth2 token is a POST request with a Content-Type
which needs to be specified as JSON; the response will also be in JSON
format:
Request example:
curl -X POST
-d '{"username": "youremail#email.com", "password": "YOURPASSWORD"}'
-H "Client_id: xxxxxxxxxxxxxxxxxxxxxxxx"
-H "Client_secret: xxxxxxxxx"
-H "Cache-Control: no-cache"
-H "Content-Type: application/json"
"https://sandbox-us-api.experian.com/oauth2/v1/token"
The following solution took care of my issue should anyone else need it for future reference. Thank you to R Community on helping to get me up to date on how this call is performed.
post_req <- httr::POST(
"https://sandbox-us-api.experian.com/oauth2/v1/token",
add_headers(
"Content-Type" = "application/json",
"Cache-Control"="no-cache",
"Client_secret"="xxxxxxxxxx",
"Client_id"="xxxxxxxxxxxxxxxxx"),
body = '{"username": "youremail#email.com", "password": "YOURPASSWORD"}',
verbose()
)
I'm trying to use the Microsoft cognitive API for text analysis using the recommended curl method from their documentation:
curl -v -X POST "https://westus.api.cognitive.microsoft.com/text/analytics/v2.0/sentiment" -H "Content-Type: application/jscp-Apim-Subscription-Key: {bc94cba9b84748ebb2f2b79a28ee3450}" --data-ascii "{I had a wonderful experience! The rooms were wonderful and the staff were helpful.}"
But I get back:
{ "statusCode": 401, "message": "Access denied due to invalid subscription key. Make sure to provide a valid key for an active subscription." }
I also tried removing the {} surrounding token and text to be analyzed. What am I doing wrong here?
Note: yes I realize the security issue with showing key but I have re-generated thanks.
There are three issues with your request:
Content-Type header should be application/json. This is likely a copy-paste error.
Ocp-Apim-Subscription-Key header value must be the API without the curly braces. This is the cause for your 401 error.
The body must be JSON of a particular format. You can find the schema here.
Here's the rewritten request:
curl -v "https://westus.api.cognitive.microsoft.com/text/analytics/v2.0/sentiment" -H "Content-Type: application/json" -H "Ocp-Apim-Subscription-Key: $OXFORD_TEXT_KEY" --data-ascii '{"documents":[{"language":"en","id":"1234","text":"I had a wonderful experience! The rooms were wonderful and the staff were helpful."}]}'
Which should result in:
{"documents":[{"score":0.9750894,"id":"1234"}],"errors":[]}
Looking at the Apigee docs, there doesn't seem to be an indication of the maximum allowed file size for assets in API BaaS.
Currently I'm trying to POST a 39MB archive using the following CURL command:
curl -X PUT -i -F name="archive" -F file=#"/path/to/archive.zip" "https://api.usergrid.com/{org}/{app}/archives/{uuid}"
And it's throwing back:
HTTP/1.1 413 Request Entity Too Large
Content-Type: application/json
Content-Length: 98
Connection: Close
{
"fault":
{
"faultstring": "Body buffer overflow",
"detail":
{
"errorcode": "protocol.http.TooBigBody"
}
}
}
Try setting the request.streaming.enabled property on TargetEndpoint. This will bypass buffering in the message processor.
See: http://apigee.com/docs/api-services/content/endpoint-properties-reference
Note: You'll also need to set response.streaming.enabled when you retrieve larger payloads.