我(试图)学习
Swift的苹果语言.我在游乐场使用Xcode 6 Beta.我正在尝试一个简单的JSON Post到本地的NodeJS服务器.我已经google了,主要的教程解释了如何在一个项目中做,而不是在PLAYGROUND,而不是写愚蠢的想法就像:“google it”或“显而易见”或“看这个链接”测试 – 和 – 不官能码
这是我正在尝试的:
var request = NSURLRequest(URL: NSURL(string: "http://localhost:3000"),cachePolicy: NSURLRequestCachePolicy.ReloadIgnoringLocalCacheData,timeoutInterval: 5) var response : NSURLResponse? var error : NSError? NSURLConnection.sendSynchronousRequest(request,returningResponse: &response,error: &error)
我试过:
var dataString = "some data" var request = NSMutableURLRequest(URL: NSURL(string: "http://posttestserver.com/post.PHP")) request.HTTPMethod = "POST" let data = (dataString as NSString).dataUsingEncoding(NSUTF8StringEncoding) var requestBodyData: NSData = data request.HTTPBody = requestBodyData var connection = NSURLConnection(request: request,delegate: nil,startImmediately: false) println("sending request...") connection.start()
谢谢! 原文链接:https://www.f2er.com/iOS/330358.html