Note that there are some explanatory texts on larger screens.

plurals
  1. PORestKit Authentication with Multiple Parameters
    primarykey
    data
    text
    <p>I have trouble getting authentication to work with a REST API that I have on a PHP stack. The query string that allows login to work on a browser looks something like <a href="http://foo.com/gamer/index.php?module=Login&amp;action=myLogin" rel="nofollow">http://foo.com/gamer/index.php?module=Login&amp;action=myLogin</a>... I followed every available documentation on RestKit and came up with the following code, in addition to enabling the NSLogConfigure, the output of which follows the code. Code</p> <pre><code>- (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&lt;RKParser&gt; parser = [[RKParserRegistry sharedRegistry] parserForMIMEType:RKMIMETypeJSON]; NSError *error = nil; NSString *json = [parser stringFromObject:moreParams error:&amp;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&amp;action=mylogin" params:authParams delegate:self]; } </code></pre> <p>RKLogConfigureByName() Output</p> <pre><code> 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 '&lt;NSMutableURLRequest http://localhost/gamer/index.php&gt;'. 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: &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml" dir="ltr"&gt; &lt;head&gt;… &lt;/head&gt; &lt;body&gt;... &lt;/body&gt; &lt;/html&gt; </code></pre> <p>As you can see from the log, the query string (authentication parameters) are included in the HTTP body. Is that fine? Also, I do get the http response status code 200 (OK), but then I just see the entire HTML code produced by the webpage at index.html. Not sure where I am going wrong? How do I decipher the RestKit response?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload