草庐IT

Alamofire

全部标签

swift - Alamofire 快速格式化 POST/PUT 参数

我在iOS(swift)上使用Alamofire时遇到问题:当我尝试使用这样的参数发送请求(在.POST或.PUT中)时:parameters:["description":WhoGives,"images":({container=offerImages;name="563f993e4b00ddad7ed42790_0.jpg";},{container=offerImages;name="563f993e4b00ddad7ed42790_1.jpg";})]它会产生一个像这样的httpBody:description="WhoGives"&images[][container]=“

swift - 将 Alamofire 调用转换为 URLSession

我有一个旧的代码库,我正试图从中迁移出去。网络调用目前使用Alamofire4.0,我正在尝试使用URLSession。我无法弄清楚出了什么问题,这就是我一直在做的事情。我从要发布的路线和参数开始://routetousercreationleturl=...letparams=["user":["first_name":"John","last_name":"Appleseed","email":"john@apple.com","password":"asdfgh"]]这是新旧网络调用://oldnetworkrequestAlamofire.request(url,method:

ios - 如何为 Alamofire 请求全局设置基本 url?

到目前为止,我创建的url请求是这样的:Alamofire.request("https://httpbin.org/room/\(user)/\(password)",method:.patch)每次我创建一个请求时,我都必须将基本url放入每个请求中。我可以以某种方式将基本url声明为全局常量吗?(此处https://httpbin.org/) 最佳答案 你应该使用一个像这样的结构的常量文件//Constants.swiftstructApi{staticletBaseUrl="https://httpbin.org"}然后,在

ios - Swift 3.0,Alamofire 4.0 调用中的额外参数 'method'

我已经阅读了关于这个问题的所有问题this和this.我有以下代码letfullURL=God.getFullURL(apiURL:self.apiUrl)if(getOrPost==God.POST){Alamofire.request(fullURL,method:.POST,AnyObject:self.postData?,encoding:.JSONEncoding.default,headers:nil).responseJSON{responseinself.responseData=response.result.value}}elseif(getOrPost==God.

ios - swift Alamofire : How to validate both a valid request and a valid response code

我们有这个Alamofire错误处理:Alamofire.request(.GET,getUrl("mystuff")).responseData{responseinguardresponse.result.error==nilelse{//Handleerror}}如果无法访问服务器或证书无效等,它会很好地工作。但是如果可以访问服务器但返回404/etc响应代码,则不会触发此错误处理代码。如何将对此用例的支持折叠到此代码中? 最佳答案 response的result属性包含代码,如果它不是nil。否则,您可以获得状态代码。ifl

swift - 为什么 Alamofire 对单元测试的超时预期使用 30 秒?

我正在研究Alamofire如何为NSOperation执行单元测试。这是其他测试使用的基本测试类。知道为什么它使用30秒作为预期的timeout吗?importAlamofireimportFoundationimportXCTestclassBaseTestCase:XCTestCase{lettimeout:NSTimeInterval=30.0funcURLForResource(fileName:String,withExtension:String)->NSURL{letbundle=NSBundle(forClass:BaseTestCase.self)returnbun

ios - 在 Alamofire 中获取 HTTP 状态行

我在swift3中使用Alamofire4.0.1库;我正在寻找HTTP状态行(如https://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html中所述)。我可以获得状态代码、header以及所有内容,但无法获取状态消息。我正在查询一个RESTAPI,它在描述问题的“Forbidden”关键字后给出了403个不同消息的响应:比如客户端未被批准访问或不允许访问特定URL,因为它是用于内部仅使用。在访问API的客户端中,我想为用户提供更多详细信息,而不仅仅是“禁止”消息。这是服务器发回的内容(我知道这一点是因为我使用了Paw,一个HTTP客户端来

swift - Rx swift : onDisposed activated before Alamofire return data

我正在尝试使用rxSwift和Alamofire从REST(swift2.3)获取JSON数据。这是我的代码:funcgetArticles(articlesReq:ArticlesReq)->Observable{returnObservable.create{observerinletrequest=Alamofire.request(.POST,apiPath,parameters:DataHelper().convertStringToDictionary(JSONString),encoding:.JSON).responseArray{(response:Response)

ios - Alamofire laravel 中字符 0 周围的无效值

我使用alamofire将发布数据发送到服务器,但它无法发送到我的服务器我使用laravel获取用户数据这是我的代码ViewControllerAlamofire.request("mysite/api/user",method:.post,parameters:["uids":uids],encoding:JSONEncoding.default).responseJSON{responseinswitchresponse.result{case.success:print(response)breakcase.failure(leterror):print(error)}}在php

ios - Alamofire 4 从类型 '(_) throws -> ()' 的抛出函数到非抛出函数类型 '(DataResponse<Any>) -> Void' 的无效转换

我刚刚运行了podupdate命令。并在我的Alamofire请求的.responseJSON{responseinblock中收到此错误。Invalidconversionfromthrowingfunctionoftype'(_)throws->()'tonon-throwingfunctiontype'(DataResponse)->Void'这里是截图更新1这是我的代码Alamofire.request(getPublicKeyUrl!,method:.get,parameters:nil,encoding:JSONEncoding.default).downloadProgr