【发布时间】:2016-01-10 16:30:30
【问题描述】:
我正在尝试在我的应用中实现错误报告页面。用户提供用户名和密码以及错误标题和描述,我做 REST(哈哈)。无论如何,这是我的代码:
+(void)reportBug:(NSString *)username password:(NSString *)password title:(NSString *)title description:(NSString *)body completion:(void (^)(id))completion{
NSDictionary *myDict = @{@"body" : body, @"title" : title, @"assignee" : username};
AFHTTPSessionManager *session = [[AFHTTPSessionManager alloc]initWithBaseURL:[NSURL URLWithString:@"https://api.github.com"] sessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
[session POST:@"/repos/AFNetworking/AFNetworking/issues" parameters:myDict constructingBodyWithBlock:nil progress:nil success:^(NSURLSessionDataTask *task, id responseObject) {
NSLog(@"everything is %@", responseObject);
} failure:^(NSURLSessionDataTask *task, NSError *error) {
completion (error);
}];
}
我并没有真正发现文档非常清楚,但也许我只是愚蠢。我收到此错误:
Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: not found (404)" UserInfo={com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x7f8a92a1de40> { URL: https://api.github.com/repos/AFNetworking/AFNetworking/issues } { status code: 404, headers {
"Access-Control-Allow-Credentials" = true;
"Access-Control-Allow-Origin" = "*";
"Access-Control-Expose-Headers" = "ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval";
"Content-Encoding" = gzip;
"Content-Security-Policy" = "default-src 'none'";
"Content-Type" = "application/json; charset=utf-8";
Date = "Sun, 10 Jan 2016 16:20:51 GMT";
Server = "GitHub.com";
Status = "404 Not Found";
"Strict-Transport-Security" = "max-age=31536000; includeSubdomains; preload";
"Transfer-Encoding" = Identity;
"X-Content-Type-Options" = nosniff;
"X-Frame-Options" = deny;
"X-GitHub-Media-Type" = "github.v3";
"X-GitHub-Request-Id" = "51AB3A71:12180:25A43C4:569284E3";
"X-RateLimit-Limit" = 60;
"X-RateLimit-Remaining" = 46;
"X-RateLimit-Reset" = 1452445261;
"X-XSS-Protection" = "1; mode=block";
} }, NSErrorFailingURLKey=https://api.github.com/repos/AFNetworking/AFNetworking/issues, com.alamofire.serialization.response.error.data=<7b226d65 73736167 65223a22 4e6f7420 466f756e 64222c22 646f6375 6d656e74 6174696f 6e5f7572 6c223a22 68747470 733a2f2f 64657665 6c6f7065 722e6769 74687562 2e636f6d 2f76332f 69737375 65732f23 63726561 74652d61 6e2d6973 73756522 7d>, NSLocalizedDescription=Request failed: not found (404)}
【问题讨论】:
-
没有。我需要吗?因为那真的没有意义
-
nvm,它是一个公共仓库。生成的请求是什么样的?看起来 API 需要 JSON,如果您发送 NSDictionary 而不是 NSString 怎么办?
-
是的,我就是这么想的。我将如何将其转换为 json 并发送?
-
只需发送一个带有键和对象的 NSDictionary,如 API 中所示。例如。 @{@"body" : 正文, @"title" : 标题,
} -
查看更新的答案。仍然出现同样的错误
标签: ios objective-c github afnetworking nsurlsession