【发布时间】:2016-06-26 10:59:33
【问题描述】:
您好,我正在将一些数据传递给 Web 服务。这是我的网址
http://www.website.com/mobileapp/user.php?reg_device_id=566&alert_details=[{\n \"is_active\" = 1;\n \"term_id\" = 55;\n}, {\n \"is_active\" = 1;\n \"term_id\" = 2;\n}, {\n \"is_active\" = 1;\n \"term_id\" = 111;\n}, {\n \"is_active\" = 0;\n \"term_id\" = 21;\n}, {\n \"is_active\" = 0;\n \"term_id\" = 28;\n}, {\n \"is_active\" = 0;\n \"term_id\" = 1;\n}, {\n \"is_active\" = 0;\n \"term_id\" = 5;\n}, {\n \"is_active\" = 0;\n \"term_id\" = 4;\n}]
这是我的网络服务调用方法
for i in 0..<dm.array.count {
let id=dm.SettingsItems[i]["term_id"] as! String
var is_active="0"
if dm.array[i]
{
is_active="1"
}
let catRegDict:NSDictionary=["term_id":"\(id)","is_active":"\(is_active)"]
self.registerAyrray.append(catRegDict)
print("------REGISTER ARRAY------\(self.registerAyrray)")
}
let urlPath = "http://www.website.com/mobileapp/user.php?"
let path="reg_device_id=\(dm.DeviceID)&alert_details=\(self.registerAyrray)"
let fullURL = "\(urlPath)\(path)"
print(fullURL)
guard let endpoint = NSURL(string: fullURL) else {
print("Error creating endpoint")
return
}
let request = NSMutableURLRequest(URL:endpoint)
NSURLSession.sharedSession().dataTaskWithRequest(request,completionHandler: { (data, response, error) in
do {
但似乎这个条件并不令人满意。我可以看到它显示此错误消息。
guard let endpoint = NSURL(string: fullURL) else {
print("Error creating endpoint")
return
}
但是当我将上面的 url 放入浏览器时,它给了我服务响应。这是什么原因?请帮我。 谢谢
【问题讨论】: