- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我有一个非常简单的场景,我正在努力应对。我正在使用 Alamofire 在 rest API 上注册用户。第一次调用注册成功,用户可以登录。第二次调用,当尝试使用相同的电子邮件地址注册时,服务器应返回 HTTP 状态代码 409。然而,Alamofire 返回一个带有空请求和响应的 .Success 。我已经用 postman 测试了这个 API,它正确地返回了 409。
为什么 Alamofire 不返回 .Failure(error),其中错误包含状态代码信息等?
这是我每次都使用相同输入运行的调用。
Alamofire.request(.POST, "http://localhost:8883/api/0.1/parent", parameters: registrationModel.getParentCandidateDictionary(), encoding: .JSON).response(completionHandler: { (req, res, d, e) -> Void in
print(req, res, d, e)
})
最佳答案
来自 Alamofire manual :
Validation
By default, Alamofire treats any completed request to be successful, regardless of the content of the response. Calling validate before a response handler causes an error to be generated if the response had an unacceptable status code or MIME type.
您可以再次使用手册中的 validate
方法手动验证状态码:
Alamofire.request(.GET, "https://httpbin.org/get", parameters: ["foo": "bar"])
.validate(statusCode: 200..<300)
.validate(contentType: ["application/json"])
.response { response in
print(response)
}
或者您可以使用不带参数的 validate
半自动验证状态代码和内容类型:
Alamofire.request(.GET, "https://httpbin.org/get", parameters: ["foo": "bar"])
.validate()
.responseJSON { response in
switch response.result {
case .success:
print("Validation Successful")
case .failure(let error):
print(error)
}
}
关于ios - Alamofire 返回 .Success on error HTTP 状态代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34737574/
问题:假设我们有一个名为success 的C++ 字符串。 &success 和 success& 有什么区别? 这题是我期中复习的,我理解&success是获取对象的地址。但我不确定 success
我正在阅读 gearman 代码的手册页( http://manpages.ubuntu.com/manpages/precise/man3/gearman_success.3.html )。他们有两
在 Angular 中,[class]="'success'" 和 class="success" 有区别吗? 例如: ... 或 ... 如果同时使用 IIUC 后者会导致替换前者,所以我想更好
当我查看日志文件时 D:\SAS\XXX\Lev1\SASMain\BatchServer\Logs 我看到了这两行 NOTE: Libref TESTLIB successfully assigne
我正在努力完成这项工作: $http.post('/route/path', {'username': $scope.threadedUsers[currentIndex].name}). s
我正在尝试设置协议(protocol)来处理我的 javascript 函数中的成功和错误,但是当函数成功时它似乎并不合作。我收到以下错误: Failed with: TypeError: Objec
在 typescript 中,我有一个 DataAccess 类,以便所有 Ajax 调用都通过单个对象进行路由,以节省应用程序中许多地方的代码重复。 在使用这种方法时,我需要使用回调将响应返回到调用
我已经用 Spring Security 3.0.2 实现了一个登录-注销系统,一切都很好,但是对于这一点:在我添加了一个带有 invalid-session-url 属性的 session 管理标签
运行命令pip install rpy2会导致以下输出和错误消息:。我按照另一篇Stackoverflow帖子上的说明卸载并重新安装了R和相关目录,但得到了相同的错误。我还尝试安装以前版本的rpy2,
我最近在项目的测试目标中添加了一个新的单元测试,当我点击产品 > 测试时,Xcode 说“测试成功”。我相当确定测试应该失败,因为被测试的方法尚未实现。我在测试中添加了一个断点,但从未到达过;测试仍然
我正在编写一个程序来创建一个AD帐户并启用Exchange邮箱,并且从中得到一些奇怪的行为。 首先,尽管它成功创建了AD用户,但由于“找不到MyPath/先生示例”,因此无法启用邮箱。我认为这是由于A
在cd_deployer_conf文件中我们设置了Cleanup="false,这样传输包在发布后不会被删除,但是我们可以看到单个发布操作有3个不同的包喜欢 tcm_0-264891-66560.CO
我正在使用 $().each() 循环访问一些项目。我想确保这段脚本之后的操作仅在 each() 完成时执行。 示例: $('something').each(function() { // do
我正在尝试创建一个 ping 洪水程序,它将目标 IP 地址和广播 IP 地址作为参数。该程序将向广播地址发送 icmp echo 数据包,并将受害者的 IP 地址作为源。网络上所有收到数据包的主机都
我正在实现一个虚拟 LTE EPC 设置,其模块 (HSS) 之一需要 mysql 数据库。创建后,我必须运行该模块,但收到屏幕截图 1 中所示的错误。附:我对这个东西很陌生 最佳答案 您必须修改您的
#include #include #include #include #include #include #include #include #include void error(cha
我的基本代码如下, fd = open("test.file", O_RDONLY); if (read(fd, &tempch, 1) < 1) { perror("F
更新 :这似乎是在 Pipeline: Declarative 中引入的错误插件版本 1.3.5 - 降级到 1.3.4.1解决了这个问题。票证创建于: https://issues.jenkins-
我最近在 jQuery 网站上看到了弃用通知。 Deprecation Notice: The jqXHR.success(), jqXHR.error(), and jqXHR.complete()
我假设调用 status.success() 会终止后台作业。但是,当我运行它时,我仍然看到第二条日志消息: Parse.Cloud.job("Tester", function (request,
我是一名优秀的程序员,十分优秀!