Im just want to ask if anyone knows how i can post multiple data with the POST request.
This works:
$data = array(
'post_params'=>[
'Name'=>'Foo',
'LastName'=>'Bar'
]
);
This dosent work: any alternatives?
$data = array(
'post_params'=>[
'Name'=>'Foo',
'LastName'=>'Bar'
],
'post_params'=>[
'Name'=>'Foo',
'LastName'=>'Bar'
]
);
Ho can i send multiple post data at once?
You can't do it that way just because that's not how requests work, you can append nearly as many attributes as you want, but not nested arrays of data.
Gonna have to do it this way:
$data = array(
'post_params'=>[
'Name1'=>'Foo',
'LastName1'=>'Bar',
'Name2'=>'Foo',
'LastName2'=>'Bar'
]
);
Related
I have a request to do in a API and i cant make a request using body in method GET. But, as there no way to make this, the only way that i find to make is transforming a post body in a querystring and put in url.
I read some questions here, and the only way that i find to make this.
If have another way, pls tell me.
This is the body that i need transform in querystring:
{"start":{"from":1609815601000,"to":-1}, "contentToRetrieve":["sdes"]}
I did it this way:
$data = array(
'{"start":{"from":' => '1609815601000',
'"to":' => '-1}',
'"contentToRetrieve":' => '["sdes"]}'
);
#Transformando payloadBody in questystring:
$dataformated = http_build_query($data);
Response: $data
= Array
(
[{"start":{"from":] => 1609815601000
["to":] => -1}
["contentToRetrieve":] => ["sdes"]}
)
Response $dataformate: %7B%22start%22%3A%7B%22from%22%3A=1609815601000&%22to%22%3A=-1%7D&%22contentToRetrieve%22%3A=%5B%22sdes%22%5D%7D
following the example in the docs, I search in my type like that:
$params = [
'index' => $this->index,
'type' => $this->type,
"scroll" => "30s",
"size" => 10,
'body' => $json
];
$response = $this->es->search($params);
now $response includes 10 results and a _scroll_id. How can I use it to paginate my results? I am looking at this example
https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/_search_operations.html#_scrolling
then the doc suggests to do:
while (isset($response['hits']['hits']) && count($response['hits']['hits']) > 0) {
$scroll_id = $response['_scroll_id'];
$response = $client->scroll([
"scroll_id" => $scroll_id, //...using our previously obtained _scroll_id
"scroll" => "30s" // and the same timeout window
]
);
}
but not clear if I have to do a new request or if the while loop is meant to store all the results in a variable and pass it to the template.
Any practical example to show?
thanks
After first request with scroll parameter, you will receive normal payload (_shards, took, hits, etc) and _scroll_id as well from elasticsearch. In hits you will have total number of found documents, hence you have: items per page and total count of items.
To figure out counts of pages - you need to do simple math.
To receive next batch of data from elasticsearch - run this:
curl 'localhost:9200/_search/scroll ' -d '{
"scroll" : "30s",
"scroll_id" : "cXVlcnlUaGVuRmV0Y2g7NTsxMzU0MDQzNjY6QnNHMjd0bXlTZ3Ftd1dkblRUd3NQZzsxMDE1NzI4Mjc6ajFzVmtLQUdSaEduRWFRVi1GZE05UTsxMDE1NzI4MjY6ajFzVmtLQUdSaEduRWFRVi1GZE05UTsxMDE1ODAzODc6TURuUG5nbzRUVU9NUUFjSERqM2hIQTsxMDE1ODAzODg6TURuUG5nbzRUVU9NUUFjSERqM2hIQTswOw=="
}'
With scroll you can only receive next batch, you can't jump on particular page.
I using https://github.com/ParsePlatform/parse-php-sdk.
I want to send notify 2 other devices.
But it's only send notify for device token is 'abcdef'.
How to send notify 2 other devices?
Thanks all,
$query = ParseInstallation::query();
$query->equalTo('deviceToken', 'xxxxx');
$query->equalTo('deviceToken', 'abcdef');
$data = [
'data' => ['alert' => 'Hello, this is a test'],
'where' => $query,
];
ParsePush::send(
$data
);
I believe your dual equalTo queries are overwriting each other. From what I understand, equalTo matches a single value. You should be able to see this behavior by inspecting a vardump of your $query after each equalTo call.
You should instead use containedIn (http://parseplatform.github.io/parse-php-sdk/classes/Parse.ParseQuery.html#method_containedIn) and pass in an array of values that you'd like the query to match. E.g., $query->containedIn('deviceToken', ['abcdef', 'xxxxx']).
Note: I don't have a parse PHP project handy so the above code isn't tested, but the general logic should work.
I want to add this symbol [ ] to the column "Post_images"
with basis data sql server
Like this,
“post_images” : “ht tp://img*sample*com/gambar1*jpg”, “ht tp://img*sample*com/gambar2*jpg”
to
“post_images” : [“ht tp://img*sample*com/gambar1*jpg”, “ht tp://img*sample*com/gambar2*jpg”]
In json the [] indicates a set of items.
Assuming you have an array with both strings inside then calling json_encode(array) should add the [ ].
See also this tutorial for more detais.
http://www.tutorialspoint.com/json/json_php_example.htm
Please do not write json on your own. Use the php functions instead.
You have to place array for post_images
it mean if you have $data which you json_encodeing you should add your post images as sub array not string. Example
$data = array(
'param1' => "data ...",
'post_images' => array(
“ht tp://img*sample*com/gambar1*jpg”,
“ht tp://img*sample*com/gambar1*jpg”
);
);
echo json_encode($data); // will output what you where looking for
Do the the following:
'["ht tp://imgsamplecom/gambar1*jpg", "ht tp://imgsamplecom/gambar2*jpg"]'
Example:
http://sqlfiddle.com/#!9/971279/1
OK, so I have this external SOAP based webservice, and PHP SoapClient. Everything is fine with basic requests, but I need to create a parameter set that looks like this:
<DatasetList>
<DatasetID>K0001</DatasetID>
<DatasetID>K0002</DatasetID>
</DatasetList>
For a single nested DatasetID tag I'd do:
$req = array( "DatasetList" => array( "DatasetId" => "K0001" ));
$client->getWebserviceCall($req);
but I need multiple DatasetID tags... I've tried assigning DatasetID as an array, but I just get:
<DatasetList>
<DatasetID>Array</DatasetID>
</DatasetList>
Anyone help?
Did you try the array this way?
$req = array( "DatasetList" => array("DatasetID" => array("K0001", "K0002));
You can do this only by wrote the Part with the identical tags by hand. But, the rest of values can you define in a array:
// Define multiple identical Tags for a part of the Array
$soap_var= new SoapVar('
<DatasetID>1</DatasetID>
<DatasetID>2</DatasetID>
';
// Define the other Values in the normal Way as an array
$req = array(
"DatasetList" => $soap_var,
'value2'=>array('other'=>'values'
);