Lor*_*ion 87 ios swift alamofire
Alamofire.request(.GET, "url").authenticate(user: "", password: "").responseJSON() {
(request, response, json, error) in
println(error)
println(json)
}
Run Code Online (Sandbox Code Playgroud)
这是我对Alamofire的要求,因为某个时候有一定的要求,但有时我得到:
Optional(Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (Invalid value around character 0.) UserInfo=0x78e74b80 {NSDebugDescription=Invalid value around character 0.})
Run Code Online (Sandbox Code Playgroud)
我已经读过这可能是由于JSON无效,但是响应是一个静态json字符串,我在JSON验证器中验证为有效.它包含åäö字符和一些HTML.
为什么我有时会收到此错误?
小智 126
我也面临同样的问题.我尝试了responseString而不是responseJSON工作.我想这是Alamofire使用它的一个错误django.
我在Alamofire中使用多部分形式上传图像时遇到了同样的错误
multipartFormData.appendBodyPart(data: image1Data, name: "file")
Run Code Online (Sandbox Code Playgroud)
我通过替换来修复
multipartFormData.appendBodyPart(data: image1Data, name: "file", fileName: "myImage.png", mimeType: "image/png")
Run Code Online (Sandbox Code Playgroud)
希望这能有所帮助.
我遇到了同样的问题,实际上由于未设置内容类型,最终导致了服务器问题。
新增中
.validate(contentType: ["application/json"])
Run Code Online (Sandbox Code Playgroud)
到请求链为我解决了
Alamofire.request(.GET, "url")
.validate(contentType: ["application/json"])
.authenticate(user: "", password: "")
.responseJSON() { response in
switch response.result {
case .Success:
print("It worked!")
print(response.result.value)
case .Failure(let error):
print(error)
}
}
Run Code Online (Sandbox Code Playgroud)
愿这个帮助你
Alamofire.request(.GET, "YOUR_URL")
.validate()
.responseString { response in
print("Success: \(response.result.isSuccess)")
print("Response String: \(response.result.value)")
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
72122 次 |
| 最近记录: |