PHP 스택에있는 REST API로 인증을받는 데 문제가 있습니다. 브라우저에서 작동하도록 로그인 할 수있는 쿼리 문자열은 http://foo.com/gamer/index.php?module=Login&action=myLogin ...와 같습니다. RestKit에서 사용 가능한 모든 설명서를 읽고 NSLogConfigure를 활성화하는 것 외에도 다음 코드를 작성했습니다. 코드 출력은 다음과 같습니다. 코드여러 매개 변수를 사용하는 RestKit 인증
- (void)sendHTTPAuthRequestWithParams {
NSMutableDictionary* authParams = [[NSMutableDictionary alloc] init];
NSMutableDictionary* moreParams = [[NSMutableDictionary alloc] init];
//user and password params
[authParams setObject:usernameTextField.text forKey:@"login"];
[authParams setObject:passwordTextField.text forKey:@"password"];
//more parameters for rest login api
[moreParams setObject:@"Login" forKey:@"module"];
[moreParams setObject:@"mylogin" forKey:@"action"];
[moreParams setObject:authParams forKey:@"params"];
//parsing
id<RKParser> parser = [[RKParserRegistry sharedRegistry] parserForMIMEType:RKMIMETypeJSON];
NSError *error = nil;
NSString *json = [parser stringFromObject:moreParams error:&error];
[RKClient sharedClient].authenticationType = RKRequestAuthenticationTypeHTTP;
//if no error
if(!error) {
RKLogConfigureByName("RestKit/Network", RKLogLevelTrace);
[[RKClient sharedClient] post:@"/index.php?" params:[RKRequestSerialization serializationWithData:[json dataUsingEncoding:NSUTF8StringEncoding] MIMEType:RKMIMETypeJSON] delegate:self];
RKLogConfigureByName("RestKit/Network", RKLogLevelTrace);
}
//[[RKClient sharedClient] post:@"/index.php?module=Login&action=mylogin" params:authParams delegate:self]; }
RKLogConfigureByName() 출력
2012-05-24 19:59:09.513 GiantsGamer[57045:207] D restkit.network:RKRequest.m:435 Sending asynchronous POST request to URL http://www.foo.com/gamer/index.php.
2012-05-24 19:59:09.514 GiantsGamer[57045:207] T restkit.network:RKRequest.m:381 Prepared POST URLRequest '<NSMutableURLRequest http://localhost/gamer/index.php>'. HTTP Headers: {
"Content-Length" = 85; "Content-Type" = "application/json";}. HTTP Body: {"module":"Login","action":"mylogin","params":{"login":"admin","password":"admin"}}. 2012-05-24 19:59:09.736 GiantsGamer[57045:207] D restkit.network:RKResponse.m:195 NSHTTPURLResponse Status Code: 200 2012-05-24 19:59:09.737 GiantsGamer[57045:207] D restkit.network:RKResponse.m:196 Headers: {"Cache-Control" = "no-store, must-revalidate";
Connection = "Keep-Alive";
"Content-Length" = 2745;
"Content-Type" = "text/html; charset=utf-8";
Date = "Fri, 25 May 2012 02:59:09 GMT";
Expires = "";
"Keep-Alive" = "timeout=5, max=100";
Pragma = "";
Server = "Apache/2.2.21 (Unix) mod_ssl/2.2.21 OpenSSL/0.9.8r DAV/2 PHP/5.3.8";
"Set-Cookie" = "PIWIK_SESSID=a065dba239819175689b1e2a23021d01; path=/; HttpOnly";
"X-Frame-Options" = sameorigin;
"X-Powered-By" = "PHP/5.3.8";
}
2012-05-24 19:59:09.737 GiantsGamer[57045:207] T restkit.network:RKResponse.m:203 Read response body: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
<head>…
</head>
<body>...
</body>
</html>
로그에서 볼 수 있듯이이 쿼리 문자열 (인증 매개 변수)는 HTTP 본문에 포함되어 있습니다. 괜찮습니까? 또한 http 응답 상태 코드 200 (OK)이 표시되지만 index.html의 웹 페이지에서 생성 된 전체 HTML 코드가 표시됩니다. 내가 어디로 잘못 가고 있는지 확실하지 않니? RestKit 응답을 어떻게 해독합니까?
모든 매개 변수를 경로 변수에 간단한 문자열로 보내 봤습니까? 당신은 그걸 어떻게 대답합니까? – clopez
나는 그 일을 시도했지만 괜찮 았는데 ... 그러나 인증 값을 하드 코딩해야했습니다. – rajeshvenkat