Objective-c - Problems with request parameters in network requests in swift.
迷茫
迷茫 2017-05-02 09:22:47
0
1
395

That’s it. Since the project is relatively simple, Alamofire is no longer needed on the network side. I wrote NSURLSession myself

private func requestWithParameters(method:Method = .GET, parameters:[String:AnyObject], url:String ,completeHandle:(Bool,AnyObject?,NSError?) ->Void)
{
    let url = NSURL(string: url)

    //set up request
    let request = NSMutableURLRequest(URL:url!)
    request.timeoutInterval = 15
    request.HTTPMethod = method.rawValue
    
    //set up parameters
    print("parameters:\(parameters)")
    var param = "?"
    for item in parameters {
        if item.1 is String{
            param += item.0 + "=" + (item.1 as! String) + "&"
        }else{
            param += item.0 + "=" + String(format: "%i",item.1 as! Int) + "&"
        }
    }
    

Half of the code in the request is as above because one of the parameters is of type Int. Suddenly I don’t know how to splice the request parameters. I can’t turn my head around. The above writing is wrong. Please help me. Write. . .

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(1)
小葫芦
for item in parameters {

  param += "\(item.0)=\(item.1)&"
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template