how to http post special chars in swift

前端 未结 3 1368
[愿得一人]
[愿得一人] 2020-12-02 01:10

I\'m using the following to post an email and password to my server (php script). The problem I\'m having is the password contains a special char (specifically the &am

3条回答
  •  臣服心动
    2020-12-02 01:46

    Here's some sample code you can try in a playground.

    //: Playground - noun: a place where people can play
    
    import UIKit
    
    var n = NSURLComponents()
    
    let s = "blah"
    // Note that the values here should not be % encoded
    let item1 = NSURLQueryItem(name: "password1", value: "ab%&")
    let item2 = NSURLQueryItem(name: "password2", value: "ab%&%#$%^&*(")
    
    n.queryItems = [item1, item2]
    
    n.URL?.query
    
    n.queryItems?.count
    
    n.queryItems![0].name
    n.queryItems![0].value
    
    n.queryItems![1].name
    n.queryItems![1].value
    
    n.URL
    

提交回复
热议问题