swfit3.0 两种方式获取post数据
来源:互联网 发布:工口mmd动作数据 编辑:程序博客网 时间:2024/06/06 19:23
//MARK: - 同步Post方式
fileprivatefunc synchronousPost() {
// 1、创建URL对象;
let url:URL! =URL(string:"http://api.3g.ifeng.com/clientShortNews");
// 2、创建Request对象
// url: 请求路径
// cachePolicy: 缓存协议
// timeoutInterval: 网络请求超时时间(单位:秒)
var urlRequest:URLRequest =URLRequest(url: url, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10)
// 3、设置请求方式为POST,默认是GET
urlRequest.httpMethod ="POST"
// 4、设置参数
let str:String ="type=beauty"
let data:Data = str.data(using: .utf8, allowLossyConversion: true)!
urlRequest.httpBody = data;
// 5、响应对象
var response:URLResponse?
// 6、发出请求
do {
let received = try NSURLConnection.sendSynchronousRequest(urlRequest, returning: &response)
let dic =try JSONSerialization.jsonObject(with: received, options:JSONSerialization.ReadingOptions.allowFragments)
print(dic)
//let jsonStr = String(data: received, encoding:String.Encoding.utf8);
//print(jsonStr)
} catchlet error{
print(error.localizedDescription);
}
}
NetworkTool.requsetData("http://192.168.1.23/index.php?m=live&c=json_post&a=category", type: .post, parameters: ["num" : 10,"page":1]) { ( result:Any) in
var ChanarrM = [ChannelModel]()
// 将 Any类型转换成字典类型
guardlet resultDict = result as? [String :Any] else {return }
// 根据 hotWordList的 key取出内容
guardlet dataArray = resultDict["data"]as? [[String :Any]] else {return }
// 遍历字典,将字典转换成模型对象
for dictin dataArray {
let ab =ChannelModel(dict: dict as [String :AnyObject])
ChanarrM.append(ab)
}
//对模型中的tid进行排序
ChanarrM.sort(by: { (s1, s2) ->Bool in
//return s1.tid! < s2.tid!
//return s1.topicid! < s2.topicid!
return s1.catid!< s2.catid!
})
print(ChanarrM)
}
- swfit3.0 两种方式获取post数据
- 在线程中使用HttpClicent获取网络数据(get和post两种方式)
- request请求获取参数(post和get两种方式)
- request请求获取参数(post和get两种方式)
- ajax获取数据的两种方式
- Android两种方式获取网络数据
- 提交数据(get,post)l两种方式
- iOS 网络请求数据两种请求方式GET,POST
- iOS请求数据两种方式(GET、POST)
- java post方式传递数据的两种方式(http https)
- 以post方式获取远程数据
- android采用post方式获取服务器数据
- android采用post方式获取服务器数据
- android采用post方式获取服务器数据
- Http 以post方式获取数据
- get/post 方式,form/数据的获取
- Java 以post方式获取数据
- ashx 获取post数据的方式
- 背景色设置透明,兼容ie浏览器设置
- 【C#与.NET程序设计】(1)- .NET
- BIO NIO AIO
- 在eclipse导入项目如何将多个项目放入一个文件夹中
- poj 2709 painter 贪心 2017.10.10 模拟赛
- swfit3.0 两种方式获取post数据
- 《老罗的Android之旅》专栏目录
- 图片上传
- linux 安装 php5.6 集成 nginx
- startup_stm32f40xx.s: error: A3906U: Malformed via file '.\debug\startup_stm32f40xx._ia'.
- 初学springcloud微服务框架(—)
- Python学习(一)
- springboot项目解决外部tomcat通过ip+端口访问项目
- NSArray,NSDictionary,NSSet用法及区别