我想從服務器獲得json響應,但收到了我下面粘貼的錯誤。不過api調用在postman.please上可以正常工作,請問您是否可以建議解決方案我在這裏做錯了API不會以原始數據返回有效的響應。但在郵遞員上工作得很好
可選(錯誤域= NSURLErrorDomain代碼= -1012 「該操作不能完成。(NSURLErrorDomain錯誤-1012。)」 的UserInfo = 0x7f9050e1f750 {NSErrorFailingURLStringKey = https://rainforestcloud.com:9445/cgi-bin/post_manager,NSUnderlyingError = 0x7f9050fe4eb0「無法完成的操作。(kCFErrorDomainCFNetwork error -1012。)「,NSErrorFailingURLKey = https://rainforestcloud.com:9445/cgi-bin/post_manager})
這裏是我的代碼
var theRequest : NSMutableURLRequest = NSMutableURLRequest(URL: NSURL(string: base_url)!)
theRequest.HTTPMethod = "POST"
theRequest.setValue("text/html", forHTTPHeaderField: "Content-Type")
theRequest.addValue("Cloud-ID", forHTTPHeaderField: "001226")
theRequest.addValue("User", forHTTPHeaderField: "[email protected]")
theRequest.addValue("Password", forHTTPHeaderField: "rainforest")
var stringData = "confirm_message";
var requestBodyData = stringData.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)
theRequest.HTTPBody = requestBodyData;
var response: NSURLResponse?
var error: NSError?
let urlData = NSURLConnection.sendSynchronousRequest(theRequest, returningResponse: &response, error: &error)
if ((error) != nil)
{
println(error)
}
else
{
self.performSegueWithIdentifier("MeterView", sender: self)
}
theRequest.timeoutInterval = 0.20
谷歌的問題第一.. –