Note that there are some explanatory texts on larger screens.

plurals
  1. POJSON API Request after Authentication
    primarykey
    data
    text
    <p>Folks,</p> <p>in iOS, I want to send authentication for an API link after authentication I want to process another JSON Request API with Accept: application/json</p> <p>How would I do something like that?</p> <p>I tried this approach but it doesn't work:</p> <pre><code>NSMutableURLRequest * request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"URL for authentication"] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:120.0]; [request setValue:@"application/json" forHTTPHeaderField:@"Content-type"]; [request setValue:@"application/json" forHTTPHeaderField:@"Accept"]; [request setHTTPMethod:@"POST"]; //[request setHTTPBody:data]; NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; [connection start]; - (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge { if ([challenge previousFailureCount] == 0) { NSLog(@"received authentication challenge"); NSURLCredential *newCredential = [NSURLCredential credentialWithUser:@"username" password:@"pass" persistence:NSURLCredentialPersistenceForSession]; NSLog(@"credential created"); [[challenge sender] useCredential:newCredential forAuthenticationChallenge:challenge]; NSLog(@"responded to authentication challenge"); // Second JSON Request API here } else { NSLog(@"previous authentication failure"); } } - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { NSLog(@"%@",response); } - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { } - (void)connectionDidFinishLoading:(NSURLConnection *)connection { } - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { } </code></pre> <p>See this link</p> <p><a href="https://checkout.hackathon.sla-alacrity.com/catalogs/443b70de5cd4429e43e9da9b87d6468058d0ae737fd6b8771" rel="nofollow">https://checkout.hackathon.sla-alacrity.com/catalogs/443b70de5cd4429e43e9da9b87d6468058d0ae737fd6b8771</a></p> <p>it is show</p> <p>{ "error": { "message": "Invalid Accept header. Need to pass HTTP Header Accept: application/json", "type": "bad_request" } }</p>
    singulars
    1. This table or related slice is empty.
    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.
    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