草庐IT

Alamofire

全部标签

swift 2.0,Alamofire : Set cookies in HTTP Post Request

我想在我的HTTPPOST请求中设置cookie。类似于下面HTTP请求中的cookie字段,version:0.1.7Cookie:client=Android;version=0.1.7;sellerId=SEL5483318784;key=178a0506-0639-4659-9495-67e5dffa42deContent-Type:application/x-www-form-urlencoded;charset=UTF-8Content-Length:1431我如何使用Alamofire实现这一目标?我现在的Alamofire请求是这样的,Alamofire.request

ios - Alamofire 请求错误 : NSURLErrorDomain Code -1005 The network connection was lost

我正在努力将我的项目从AFNetworking转移到Alamofire。真的很喜欢这个项目。但是,我在尝试发出GET请求时收到此错误。下面是一些示例代码:classfunclistCloudCredntials(onlyNewonlyNew:Bool=true,includePending:Bool=true)->Request{letparameters:[String:AnyObject]=includePending?["include_pending":"true"]:[:]leturlString="https://myapp-staging.herokuapp.com/ap

ios - 在 Alamofire 4.0、iOS 10 和 Swift 3 中使用 Google Places API

我的项目目前是在Xcode8和带有Alamofire4.0的Swift3中构建的。我使用CocoaPods来实现Alamofire。我的播客文件如下:#Uncommentthenextlinetodefineaglobalplatformforyourprojectplatform:ios,'10.0'use_frameworks!target'WTB’do#Commentthenextlineifyou'renotusingSwiftanddon'twanttousedynamicframeworkspod'Alamofire',:git=>'https://github.com/A

ios - Alamofire 4 和 JSON 中的特殊字符

我在使用Alamofire4时遇到特殊字符的问题。JSON包含æ、ø和å,浏览器可以正常显示它们,我之前使用SwiftyJSON的解决方案也是如此。Alamofire4显示如下内容:U00e6使用这个调用:Alamofire.request(specificURL,method:.get,parameters:param,encoding:URLEncoding.default,headers:nil).responseJSON{(response:DataResponse)inprint(response)}如何解决这个问题? 最佳答案

swift - 使用 Alamofire [swift] 为每个请求设置客户端超时?

我正在尝试为AlamofireforSwift的每个请求设置客户端超时。首席架构师告诉我在NSURLRequest上设置它,但我完全不知道如何在实践中真正做到这一点。有做过的人可以举个例子吗?谢谢! 最佳答案 我认为这段代码可能有效。varalamofireManager:Alamofire.Manager?funcsome(){letconfiguration=NSURLSessionConfiguration.defaultSessionConfiguration()configuration.timeoutIntervalFo

swift - 取消所有来自 Alamofire 的网络服务调用

在我的项目中有4个Web服务在后台运行。我想在不等待响应的情况下从当前状态注销时停止所有这些服务。我找到了这样做的代码Alamofire.Manager.sharedInstance.session.invalidateAndCancel()但是在调用这个之后,我无法再次调用服务电话。有什么办法可以取消所有正在运行的请求吗?这是我的服务调用代码funcgetAllCount(parameters:[String:AnyObject],completion:(success:Bool)->Void){PKHUD.sharedHUD.contentView=PKHUDTextView(te

ios - 使用 Alamofire 请求获取图像数据

我已将我的代码更新为Swift3,但在迁移到Alamofire4.0时遇到了问题。我已经使用Alamofire迁移指南成功进行了大部分必要的修改,但在获取图像数据时仍然遇到问题。旧的Swift2/Alamofire3代码(按预期工作):funcbeginGetImageRequest(){ifletimagePath=thumbPath{request=Alamofire.request(.GET,imagePath).response(completionHandler:{(_,_,imageData,error)->Voidiniferror!=nil{NSLog("Errordo

ios - 了解 AlamoFire OAuth 示例

我能够获得AlamoFire提供的OAuth示例的有效实现。但是,我希望了解某些代码行及其工作原理。完整示例:classOAuth2Handler:RequestAdapter,RequestRetrier{privatetypealiasRefreshCompletion=(_succeeded:Bool,_accessToken:String?,_refreshToken:String?)->VoidprivateletsessionManager:SessionManager={letconfiguration=URLSessionConfiguration.defaultcon

ios - Alamofire 接受和内容类型 JSON

我正在尝试在Swift中使用Alamofire发出GET请求。我需要设置以下header:Content-Type:application/jsonAccept:application/json我可以绕过它并直接指定请求的header,但我想按照库中的建议使用ParameterEncoding来完成。到目前为止我有这个:Alamofire.request(.GET,url,encoding:.JSON).validate().responseJSON{(req,res,json,error)inif(error!=nil){NSLog("Error:\(error)")println(

ios - 使用新的 Swift 3 和 Alamofire 解析 JSON

我正在使用Alamofire作为HTTP库,自从更新到Swift3之后,您如何根据下面的示例解析JSON?Alamofire.request("https://httpbin.org/get").responseJSON{responseindebugPrint(response)ifletjson=response.result.value{print("JSON:\(json)")}}respone.result.value是Any对象的,很新很容易混淆。 最佳答案 正如您在Alamofiretests中看到的那样你应该将res