412对Github的第二次请求的响应

时间:2014-01-16 15:57:58

标签: ios7 github-api afnetworking-2

我使用AFNetworking 2.0访问Github API时遇到了一些非常奇怪的行为。我第一次向此终点http://developer.github.com/v3/oauth/#get-or-create-an-authorization-for-a-specific-app发出API请求以获取OAuth令牌时,它会返回200或201响应。如果我退出应用程序并再次尝试,请求将返回412响应,即使请求相同。我无法使用curl重现这一点。我会在这里粘贴请求和回复。

请求通过的响应1

PUT 'https://api.github.com/authorizations/clients/a162f34fd261c382b59d': {
    "Accept-Language" = "en;q=1, fr;q=0.9, de;q=0.8, zh-Hans;q=0.7, zh-Hant;q=0.6, ja;q=0.5";
    Authorization = "Basic ****************************";
    "Content-Type" = "application/json; charset=utf-8";
    "User-Agent" = "Staticly/1.0 (iPad Simulator; iOS 7.0.3; Scale/1.00)";
} {"client_secret":"*****************************","scope":["repo"]}

2014-01-08 10:43:26.313 Staticly[6035:70b] PUT 'https://api.github.com/authorizations/clients/a162f34fd261c382b59d': {
    "Accept-Language" = "en;q=1, fr;q=0.9, de;q=0.8, zh-Hans;q=0.7, zh-Hant;q=0.6, ja;q=0.5";
    Authorization = "Basic **************************";
    "Content-Type" = "application/json; charset=utf-8";
    "User-Agent" = "Staticly/1.0 (iPad Simulator; iOS 7.0.3; Scale/1.00)";
} {"client_secret":"*******************************","scope":["repo"]}
2014-01-08 10:43:26.364 Staticly[6035:70b] 200 'https://api.github.com/authorizations/clients/a162f34fd261c382b59d' [0.0510 s]: {
    "Access-Control-Allow-Credentials" = true;
    "Access-Control-Allow-Origin" = "*";
    "Access-Control-Expose-Headers" = "ETag, Link, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval";
    "Cache-Control" = "private, max-age=60, s-maxage=60";
    "Content-Encoding" = gzip;
    "Content-Type" = "application/json; charset=utf-8";
    Date = "Wed, 08 Jan 2014 15:43:24 GMT";
    Etag = "\"257ff8977266fd375142f862e0536b53\"";
    Server = "GitHub.com";
    Status = "200 OK";
    "Transfer-Encoding" = Identity;
    Vary = "Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding";
    "X-Content-Type-Options" = nosniff;
    "X-GitHub-Media-Type" = "github.beta";
    "X-GitHub-Request-Id" = "633B6CDC:6F7C:9F9595F:52CD721C";
    "X-RateLimit-Limit" = 5000;
    "X-RateLimit-Remaining" = 4985;
    "X-RateLimit-Reset" = 1389198563;
} (null)

请求响应2失败

PUT 'https://api.github.com/authorizations/clients/a162f34fd261c382b59d': {
    "Accept-Language" = "en;q=1, fr;q=0.9, de;q=0.8, zh-Hans;q=0.7, zh-Hant;q=0.6, ja;q=0.5";
    Authorization = "Basic *********************";
    "Content-Type" = "application/json; charset=utf-8";
    "User-Agent" = "Staticly/1.0 (iPad Simulator; iOS 7.0.3; Scale/1.00)";
} {"client_secret":"************************","scope":["repo"]}

2014-01-08 10:45:39.187 Staticly[6078:70b] PUT 'https://api.github.com/authorizations/clients/a162f34fd261c382b59d': {
    "Accept-Language" = "en;q=1, fr;q=0.9, de;q=0.8, zh-Hans;q=0.7, zh-Hant;q=0.6, ja;q=0.5";
    Authorization = "Basic ***************************";
    "Content-Type" = "application/json; charset=utf-8";
    "User-Agent" = "Staticly/1.0 (iPad Simulator; iOS 7.0.3; Scale/1.00)";
} {"client_secret":"*************************","scope":["repo"]}
2014-01-08 10:45:39.188 Staticly[6078:70b] 412 'https://api.github.com/authorizations/clients/a162f34fd261c382b59d' [0.0018 s]: {
    "Access-Control-Allow-Credentials" = true;
    "Access-Control-Allow-Origin" = "*";
    "Access-Control-Expose-Headers" = "ETag, Link, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval";
    "Cache-Control" = "private, max-age=60, s-maxage=60";
    "Content-Type" = "text/html;charset=utf-8";
    Date = "Wed, 08 Jan 2014 15:45:37 GMT";
    Etag = "\"257ff8977266fd375142f862e0536b53\"";
    Server = "GitHub.com";
    Status = "412 Precondition Failed";
    "Transfer-Encoding" = Identity;
    "X-Content-Type-Options" = nosniff;
    "X-GitHub-Request-Id" = "633B6CDC:6F7A:91EF162:52CD72A1";
    "X-RateLimit-Limit" = 5000;
    "X-RateLimit-Remaining" = 4983;
    "X-RateLimit-Reset" = 1389198563;
} (null)

1 个答案:

答案 0 :(得分:3)

我在挖掘OctoKit源代码后想出了这个。 Github不喜欢[NSURLSessionConfiguration defaultSessionConfiguration]设置的缓存策略。将缓存策略设置为NSURLRequestReloadIgnoringLocalCacheData可以解决问题。