Note that there are some explanatory texts on larger screens.

plurals
  1. PORestful API call using IOS with authentication
    text
    copied!<p>I am working on an application that uses restful API call using prestashop API. I am new at IOS I coded the same method in android as: </p> <pre><code> InputStream is = null; try { DefaultHttpClient client = new DefaultHttpClient(); /* adding credentials as it is RESTful call */ String username = "xyz"; String password = ""; client.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),new UsernamePasswordCredentials(username, password)); // HTTP get request HttpGet get = new HttpGet("http://www.example.com/api/"); HttpResponse responseGet; responseGet = client.execute(get); is = responseGet.getEntity().getContent(); } catch (ClientProtocolException e) { Log.e("HTTP Request","Client Protocol exception" ); } catch (IOException e) { Log.e("HTTP Request","IO exception" ); } </code></pre> <p>It is working perfectly for Android. For IOS I used this coding but I am not getting data from the server.</p> <pre><code>NSString *userName = @"XYZ"; NSString *password = @""; //setting the string of the url taking from appliance IP. NSString *urlString = @"http://www.example.com/api/"; NSMutableURLRequest *request= [[NSMutableURLRequest alloc] init]; [request setURL:[NSURL URLWithString:urlString]]; [request setHTTPMethod:@"GET"]; NSString *str1 = [NSString stringWithFormat:@"%@:%@",userName,password]; NSLog(@" str1 %@", str1); [request addValue:[NSString stringWithFormat:@"Basic %@",str1] forHTTPHeaderField:@"Authorization"]; NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; NSString *str = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding]; NSLog(@"str: %@", str); </code></pre> <p>please tell me what I am doing wrong and provide any solution. </p> <p>Thanks!</p>
 

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