Mudassar Saiyed Mudassar Saiyed - 1 year ago 96
iOS Question

Can't send parameter through alamofire to webservice

I want to send parameter through Alamofire to webservice. I have checked the webservice and it is working properly but it is not accepting parameter just getting response of else part.

Here is my Alamofire code I am using in swift iOS.

let parameters: Parameters = [

"signers": "ram,Rahim",
"message": "hello,World",
"path": "",

Alamofire.request("", parameters: parameters).responseJSON(completionHandler: { (response) in

Here is the code of Webservice - esp.php

//Turn off all error reporting

if( $_SERVER['REQUEST_METHOD']=='POST' && $_POST['signers'] && $_POST['message'] && $_POST['path'] && $_POST['sequence']){

$path_s = $_POST['path'];
$path_array = explode(',', $path_s);

$signer_s = $_POST['signers'];
$signer_array = explode(',', $signer_s);

$message_s =$_POST['message'];
$message_array = explode(',', $message_s);

$sequence_s =$_POST['sequence'];
$sequence_array = explode(',', $sequence_s);

for ($i = 0; $i < count($signer_array); $i++) {

$signer = ($signer_array[$i]);
$path = ($path_array[0]);
$message = ($message_array[0]);
$sequence =($sequence_array[$i]);

$con = mysql_connect('','user_pixcel','abc123') or die('Cannot connect to the DB');

$query = mysql_query("INSERT INTO `path` (url,name,signer,sequence,message,flag)
VALUES ('".$path."','".$name."','".$signer."','".$sequence."','".$message."','false')");
// echo "Data inserted";
$return['url'] = 'true';
$return['data'] = "Data inserted";

header('Content-type: application/json');
exit( json_encode( $return ) );

} else {
$return['message']='Data not inserted!';

header('Content-type: application/json');
exit( json_encode( $return ) );


Answer Source


Well based from the Alamofire docs if you don't specify HTTPMethod:

The Alamofire.request method parameter defaults to .get.

So judging on that, I think the request being sent there is .get, and it has no parameters attached to it.


Change your code to:

Alamofire.request("", method: .post, parameters: parameters).responseJSON(completionHandler: { (response) in
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download