zoukankan      html  css  js  c++  java
  • Alamofire的get请求,post请求,以及上传字典

    get请求:

    Alamofire.request("你的网址",method: .get, parameters: nil, encoding: URLEncoding.default)

                .responseJSON { response in

              //print("url:(response.request)")  // original URL request

              //print("request:(response.response)") // URL response

              //print("data:(response.data)")     // server data

              //print("result:(response.result)")   // result of response serializatio

            }

    post请求:

     let currRequest = Alamofire.request("你的网址", method: .post, parameters: nil, encoding:URLEncoding.default, headers: nil)

                currRequest.responseJSON{(responseJson) -> Void in

                    

                    switch responseJson.result {

                    case .success(let value):

                        let swiftyJsonVar = JSON(value)

                        //将获取的所有的title放到数组里面

    //                    let str = swiftyJsonVar["data"].arrayValue.map({$0["title"].stringValue})

                        self.resultArr = swiftyJsonVar["data"]

    //                    for index in 1...self.resultArr.count{

    //                        if let str = self.resultArr[index-1]["title"].string {

    //

    //                             print(str)

    //                        }

    //                    }

                    case .failure( _):

    //                    print(error)

                     

                         ZHBPopTipView.showText("网络错误", position: .bottom)

                    }

                    self.tableView.reloadData()

                }

     


    post接口并上传字典:

      do {

                 dic = ["key":"value"]

                 print(mobileDic)

                Alamofire.request("你的网址", method: .post, parameters:dic, encoding: URLEncoding.default, headers:nil).responseJSON(completionHandler: { (response)in

                    switch response.result{

                    case .success:

                        iflet dic:NSDictionary = (response.result.value as? NSDictionary){

                            print(dic)

                        }

                    case .failure(let error):

                        print(error)

                    }

                })

            } catch  {

                print(error)

            }

  • 相关阅读:
    标题党的进步:道字大旗不再扯,美为号召又开张
    dwr自动生成的js文件到底在哪里?
    JavaScript全局优化带来的负面效果……
    内训资料公开:设计师的实战过程(1)
    元语言基础技术之:在JS中如何自由地创建函数
    QoBean的元语言系统(一)
    Oracle面向服务的架构
    对JavaScript的eval()中使用函数的进一步讨论~
    KEGG and Gene Ontology Mapping in Bioinformatic Method
    mysql user administration
  • 原文地址:https://www.cnblogs.com/-ios/p/7279367.html
Copyright © 2011-2022 走看看