發(fā)出POST請求時,Xcode調(diào)試器顯示錯誤錯誤域= NSCocoaErrorDomain代碼= 3840“ JSON文本不是以數(shù)組或?qū)ο箝_頭,并且沒有允許設置片段的選項?!?UserInfo = {NSDebugDescription = JSON文本不是以數(shù)組或?qū)ο箝_頭,并且未設置允許片段的選項。}這是POST函數(shù), func startArchive() { let app_Id = (appId.base64Decoded()!) let job_Id = (jobId.base64Decoded()!) var response_ = 0 guard let url = URL(string: "https://xxx.yyyy.com/question/abc") else {return} let request = NSMutableURLRequest(url:url) request.httpMethod = "POST" let postString = "session_id=\(pSessionId)&job_id=\(job_Id)&app_id=\(app_Id)&action=start" print(postString) request.setValue("application/x-www-form-urlencoded; charset=utf-8", forHTTPHeaderField: "Content-Type") request.httpBody = postString.data(using: String.Encoding.utf8) let task = URLSession.shared.dataTask(with: request as URLRequest) { data, response, error in guard error == nil && data != nil else { // check for fundamental networking error print("error=\(String(describing: error))") return } do { if let responseJSON = try JSONSerialization.jsonObject(with: data!) as? [String:AnyObject]{ print(responseJSON) print(responseJSON["status"]!) response_ = responseJSON["status"]! as! Int print(response_) //Check response from the sever if response_ == 200 { OperationQueue.main.addOperation { print("Login Successful") } }
- 1 回答
- 0 關注
- 259 瀏覽
添加回答
舉報
0/150
提交
取消