大佬教程收集整理的这篇文章主要介绍了在Swift中的cURL等价 – iOS,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
curl -X POST -F "file=@/Users/nicolas/sample.png" -F "mode=document_photo" https://api.idolondemand.com/1/api/sync/ocrdocument/v1 -F "apikey=xxx-xxx-xxx-xxx-xxx"
相应的代码发布在下面.
func getText (image: UIImage){ let apiKey = "xxx-xxx-xxx-xxx-xxx" let request = NSMutableURLRequest(URL: NSURL(string: "https://api.idolondemand.com/1/api/sync/ocrdocument/v1")!) request.HTTPMethod = "POST" request.addValue(apiKey,forHTTPHeaderField: "apikey") request.addValue("document_photo",forHTTPHeaderField: "mode") request.HTTPBody = UIImageJPEGRepresentation(image,1) let task = NSURLSession.sharedSession().uploadTaskWithRequest(request,fromData: UIImageJPEGRepresentation(image,1),completionHandler: {data,response,error -> Void in if let _ = data { var error:NSError? = nil do { let jsonObject : AnyObject = try NSJSONSerialization.JSONObjectWithData(data!,options: []) let json = JSON(jsonObject) if let ocr_results = json["text_block"][0]["text"].string { self.returnText(ocr_results) } } catch let error1 as NSError { error = error1 print(error) } catch { fatalError() } } })
如果我收到回复,我会很高兴.
以上是大佬教程为你收集整理的在Swift中的cURL等价 – iOS全部内容,希望文章能够帮你解决在Swift中的cURL等价 – iOS所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。