I need to do this GET call with matlab:
curl -X GET \
-H "X-Parse-Application-Id: my_AppKEY" \
-H "X-Parse-REST-API-Key: my_APIKEY" \
https://api.parse.com/1/classes/GameScore
(this is a basic request to parse.com)
In matlab 2014b I have the function webread which becomes a weboptions struct.
I think the correct way of setting a header for the request is like this:
myHeaders1 = weboptions('KeyName', 'X-Parse-Application-Id', 'KeyValue' , 'my_KEY')
The thing is... I can only set 1 header using this syntax. How can I set 2 or more headers to be used in webread?
You can either call curl from within Matlab if you load right library files or instead you can use urlread2
Related
I want to send ['1', '2', '3'] as a GET request.
I thought GET request are used when you are retrieving data opposed to POST (when you are modifying/creating data)
Failing to google how to send list of strings with GET does make me wonder, if it's better to use POST here?
Once you intend to perform a GET request, you could send data in the query string using one of the following approaches:
curl -G http://example.org -d "query=1,2,3"
curl -G http://example.org -d "query=1&query=2&query=3"
Let me highlight that payloads in GET requests are not recommended. Quoting the RFC 7231:
A payload within a GET request message has no defined semantics; sending a payload body on a GET request might cause some existing implementations to reject the request.
Also bear in mind that GET requests shouldn't be used to modify resources: they are intended to be used for information retrieval only, without side effects. Having said that, GET is both safe and idempotent. You can see more details on these concepts in this answer.
If the data must be sent in the payload (and you intend to modify the resource) then stick to POST. Assuming your payload is a JSON document, you would have something like:
curl -X POST http://example.org \
-H "Content-Type: application/json" \
-d '["1", "2", "3"]'
If you want to send it in the body with curl you can call your service like this:
curl -X GET --data "['1', '2', '3']" "https://example.com/test.php"
For example in PHP you can read it from the read-only stream php://input
<?php
$get_body = file_get_contents('php://input');
A better way would be to assign the array to a parameter e.g. x:
curl -X GET "https://example.com/test.php?x[]=1&x[]=2&x[]=3"
In PHP you'll receive these values as an array in $_GET['x']:
<?php
print_r($_GET['x']);
Output:
Array
(
[0] => 1
[1] => 2
[2] => 3
)
I want run AutoML in h2o by using rest api? I know the url is /99/AutoMLBuilder. But I have no idea that how can I send the parameters. There is no sample code on the official web site. I can access model import/export by using curl because the parameters are flat. But it seems that maybe the parameters of AutoML are nested, and I cannot find any sample code or answers about the format of the parameters.
The parameters are sent in JSON format through a POST command. For example, assuming a training frame named airlines has already been loaded, you can train an AutoML model through curl with:
curl -X POST http://localhost:54321/99/AutoMLBuilder -H "Content-Type: application/json" -d '{"input_spec": {"training_frame":"airlines", "response_column":"IsDepDelayed"}, "build_control": {"project_name":"aml_curl_test", "stopping_criteria":{"max_models":3} } }'
You can find the full REST API reference here: http://docs.h2o.ai/h2o/latest-stable/h2o-docs/rest-api-reference.html, which will tell you the JSON object names each parameter belongs to.
Currently, I have a problem with Dream Factory REST API call, when a space is present into the API URL call.
I have a get request with a sort parameter that must to be send for SOLR server. This space I don’t know how it is converted, but it seems to arrive into not appropriate mananer.
curl -X GET
‘http://localhosts:81/api/v2/test/list/test?rows=10&sort=random_test%20desc’
-H ‘X-DreamFactory-Api-Key: e115f92d18ba58e9a29389’
-H ‘X-DreamFactory-Session-Token: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1’
SOLR need to have this sort parameter and the direction of the sort. So we provide the column to sort, space and the direction. When I execute this curl using Dream Factory api, then the space or the %20 character seems to be converted into other thing.
Is there someone knowing, if this is a Dream factory problem, or whether it is possible to make the call in another manner?
Finaly the solution that I found is to change the curl call in order to make POST request and to put the parameters with spaces into the -d parameter.
Here is the call working for our case :
curl -X POST \
'http://localhost:81/api/v2/test/list/test?rows=10' \
-H 'X-DreamFactory-Api-Key: e115f92d18ba58e9a2' \
-H 'X-DreamFactory-Session-Token: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJz' \
-d 'sort=random_test+DESC&fq=NAME:*ov*+OR+NAME:*a*'
I was trying to do image classification through a web at service at and
I had no problem to use curl to retrieve token:
curl -i -X POST -H "Authorization:MY Key" -F "image_request[image]=#/path/to/myimage" -F "image_request[locale]=en-US" https://api.cloudsightapi.com/image_requests
However, it is not successful when I tried webwrite, it returned "HTTP 400" error.
option=weboptions('KeyName','Authorization','KeyValue','mykey')
fid = fopen('/path/to/myimage');
img = fread(fid,Inf,'*uint8');
fclose(fid);
response=webwrite('https://api.cloudsightapi.com/image_requests',...
'image_request[image]',img,...
'image_request[locale]','en-US',option);
I guess it because the function webwrite in this format doesn't support "multipart/form-data" and I need change the media type. Then I tried to send data as an JSON object
option=weboptions('KeyName','Authorization','KeyValue','mykey','MediaType','application/json')
data=struct('image_request[image]',im,'image_request[locale]','en-US');
response=webwrite('https://api.cloudsightapi.com/image_requests',data,option)
But the field name in Matlab struct does not allow "[".
Any suggestion?
I am a little bit confused why I get such low confidences with the REST API of Spotlight.
I run the following code/call:
curl http://spotlight.dbpedia.org/rest/annotate \
--data-urlencode "text=Hallo, i am looking for a new Microsoft or Apple tablet." \
--data "confidence=0.2" \
--data "support=20"
then I just get similarityScores between 0.130 and 0.135.
When I try this text in the demo (http://dbpedia-spotlight.github.io/demo/) then I can get the results until to a confidence of 0.60.
What cause my low confidence values? How can I obtain correct values?
p.s. Is there anywhere a more comprehensive documentation?
First similarityScores does not correspond to the values of Confidence.
But more importantly http://spotlight.dbpedia.org/rest/annotate is not the endpoint being used by the demo.
The endpoint being used by the demo is: http://spotlight.sztaki.hu:2222/rest