Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift Alamofire POST请求URL_Swift_Post_Alamofire - Fatal编程技术网

Swift Alamofire POST请求URL

Swift Alamofire POST请求URL,swift,post,alamofire,Swift,Post,Alamofire,假设我有一个URL“10/timetabless” 其中,上述URL中的10是stationId,可以是任何数字 如何使用alamofire在URL中发布具有更改参数(StationId)的请求 我应该把它添加到参数部分吗? 请帮忙 目前我静态调用它,如下所示:- 阿拉莫菲尔请求( “10/timetabless”, 参数:无, 标题:无) 使用\(variableName)在字符串中插入变量或常量 标题是指定要发送和接收的内容格式的位置 标题示例: let headers: HTTPHead

假设我有一个URL“10/timetabless”

其中,上述URL中的10是stationId,可以是任何数字

如何使用alamofire在URL中发布具有更改参数(StationId)的请求

我应该把它添加到参数部分吗? 请帮忙

目前我静态调用它,如下所示:- 阿拉莫菲尔请求( “10/timetabless”, 参数:无, 标题:无)

使用
\(variableName)
在字符串中插入变量或常量

标题是指定要发送和接收的内容格式的位置

标题示例:

 let headers: HTTPHeaders = [
            "Accept": "application/json",
            "Content-Type": "application/json"
           ]
参数是放置要发送(POST)的数据的位置

参数示例:

let pararameters: [String, Any] = [
            "name": name as String,
            "id": id as Int,
           ]
使用
\(variableName)
在字符串中插入变量或常量

标题是指定要发送和接收的内容格式的位置

标题示例:

 let headers: HTTPHeaders = [
            "Accept": "application/json",
            "Content-Type": "application/json"
           ]
参数是放置要发送(POST)的数据的位置

参数示例:

let pararameters: [String, Any] = [
            "name": name as String,
            "id": id as Int,
           ]

要执行POST请求,请将参数添加到请求主体,而不是url本身

您必须遵循以下内容:

let parameters: Parameters = ["parameter-name": parameterValue]
let headers    = ["Content-Type":"application/json"]
Alamofire.request("<your post url>",method: .post, parameters: parameters, encoding: JSONEncoding.default,headers: headers)
        .responseJSON { response in
            print(response)
            // Do anything you like with the response here

    }
let参数:参数=[“参数名称”:参数值]
let headers=[“内容类型”:“应用程序/json”]
请求(“,方法:.post,参数:参数,编码:JSONEncoding.default,headers:headers)
.responseJSON{中的响应
打印(答复)
//你喜欢这里的回答吗
}

要执行POST请求,请将参数添加到请求主体,而不是url本身

您必须遵循以下内容:

let parameters: Parameters = ["parameter-name": parameterValue]
let headers    = ["Content-Type":"application/json"]
Alamofire.request("<your post url>",method: .post, parameters: parameters, encoding: JSONEncoding.default,headers: headers)
        .responseJSON { response in
            print(response)
            // Do anything you like with the response here

    }
let参数:参数=[“参数名称”:参数值]
let headers=[“内容类型”:“应用程序/json”]
请求(“,方法:.post,参数:参数,编码:JSONEncoding.default,headers:headers)
.responseJSON{中的响应
打印(答复)
//你喜欢这里的回答吗
}

谢谢!那么alamofire中“参数”的用途是什么呢?更新到那里了。谢谢!那么alamofire中“参数”的用途是什么呢。