我正在尝试在网址正文中传递两个值
它运行完美:在这里,我给出了requestedKey
值字符串
let urlStr = "http://itaag-env-1-south-1.elasticbeanstalk.com/getprofile/?requestedKey=" + "9609cc826b0d472faf9967370c095c21&requestedUserType=personal"
这里我已存储requestedKey value in personalId
let personalId: String = UserDefaults.standard.string(forKey: "USERID") ?? ""
[如果我尝试如下所示显示错误:个性值仍然显示为空
let urlStr = "http://itaag-env-1-south-1.elasticbeanstalk.com/getprofile/?requestedUserType" + "personal & requestedKey =" + personalId
[请帮助我解决此错误。
这应该如何创建具有不同组件的URL:
let string = "http://itaag-env-1-south-1.elasticbeanstalk.com/getprofile"
var urlComponents = URLComponents(string: string)
let requestedItem = URLQueryItem(name: "requestedKey", value: "yourReqKey")
let requestedUserType = URLQueryItem(name: "requestedUserType", value: "personal")
urlComponents?.queryItems = [requestedItem, requestedUserType]
let url = urlComponents?.url
print(url?.absoluteString)