Step:1使用CocoaPod 在swift项目中导入 AFNetworking框架
具体步骤-> http://code4app.com/article/cocoapods-install-usage 特别全
Step2:配置info.plist支持http请求(https还没看- -、)
根标签下添加 App Transport Security Settings ,类型 Dictionary 。添加元素 Allow Arbitrary Loads 类型布尔,值为true.
func wordsTrans(inputText:String, type:Int){ let manager = AFHTTPRequestOperationManager(); manager.GET("http://japi.juhe.cn/charconvert/change.from", parameters:["text":inputText,"type":type,"key":"用你自己的Key"], success: { (op:AFHTTPRequestOperation, responseData: AnyObject) -> Void in print("responseData = \(responseData)") let data = responseData as! NSDictionary; print(data["outstr"]!); },failure: { (operation: AFHTTPRequestOperation?,error: NSError?) -> Void in print("failure"); }) }
Bingo