post method array data in php and swift

I am sending array data with post http method, that is, I am sending more than one value. But now I'm getting a blank output. Although I post "formKATID", I get no results. How can I send Array data?
Swift
@objc func kategoriSaydД±r(){
...
var values: [String: AnyObject] = [:]
values["formKATID="] = "5" as AnyObject
request.httpBody = try! JSONSerialization.data(withJSONObject: values, options: [])
let task = URLSession.shared.dataTask(with: request) { data, response, error in
guard let data = data else {
return
}
... }
PHP
$formKATID = $_POST['formKATID'];
$tsql = "... WHERE KATEGORI.ID IN(".implode(', ',$formKATID).")";
$stmt = sqlsrv_query( $conn, $tsql);
while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) {
Answer
Solution:
You're posting a dictionary where the key isformKATID=
and the value is the string"5"
. Then in your php code you are looking for the keyformKATID
. Those are not equal, so you will need to remove the=
.
And if usingURLSession
seems confusing I made a really basic pod (or use something like Alamorfire) that wraps around it so that all you would need to do is:
networkUtils.post(url, dictionary).then { data in
// Use data response here
}.catch { error in
// Catch error here
}
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: illuminate\http\exceptions\posttoolargeexception
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.