[英]Send POST request using postman but receiving GET request in php. I try to create API using postman
[英]Try to post array of objects from postman to php api and get errors
我認為您這樣做的方式是不可能的,您只能使用POST
和GET
傳輸字符串,嘗試僅用一個KEY
發送所有數據,然后在服務端對其進行json_decode
。 所以嘗試發送這樣的東西
[
{
"id": 1,
"flowID": 1,
"fileID": 1,
"type": "partner",
"page": 1
}
]
作為VALUE
,使用KEY
: signatures
,然后在 PHP 代碼中:
<?php
$signatures = json_decode($_POST["signatures"]); // <=== this is an array now
print_r($signature);
您正在嘗試過濾一個數組,但您沒有編寫如何過濾它(第二個參數)
<?php
$signatures = $_POST["signatures"];
$signature = array_filter($signatures,<**variabile or function to be filtered**>);
echo json_encode($signature);
如何發送對象數組:將郵遞員設置為 application/json 並發布正文:
[
{
"id": 1,
"flowID": 1,
"fileID": 2,
"type": "identification",
"page": 1,
"positionX": 160,
"positionY": 241,
"sizeWidth": 150,
"sizeHeight": 250
},
{
"id": 2,
"flowID": 4,
"fileID": 2,
"type": "partner",
"page": 1,
"positionX": 160,
"positionY": 241,
"sizeWidth": 150,
"sizeHeight": 250
}
]
獲取請求正文並使其成為數組:
$rawPostBody = file_get_contents('php://input');
$signatures = (array)json_decode($rawPostBody);
循環遍歷數組:
foreach($signatures as $signature) {
echo $signature->type;
}
希望這可以幫助那些曾經尋找如何去做的人。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.