objective c - Accessing the Arcgis secured url using authentication ios -


here trying access secured url using http authentication. still data coming null. code:

{    nsurl *url = [nsurl urlwithstring:@"http://mysecuredurl.com"];      nsstring *username =@"abc@v.com";     nsstring *password =@"12345";     nserror *myerror = nil;     nsmutablestring *loginstring = (nsmutablestring*)[@"" stringbyappendingformat:@"%@:%@", username, password];   nslog(@"loginstring=%@",loginstring);     nsstring *authheader = [@"basic " stringbyappendingformat:@"%@", loginstring];    nslog(@"auth header =%@",authheader);     nsmutableurlrequest *request = [nsmutableurlrequest requestwithurl: url                                                           cachepolicy: nsurlrequestreloadignoringcachedata                                                        timeoutinterval: 3];    nslog(@"request %@",request);  [request addvalue:authheader forhttpheaderfield:@"authorization"];    nsurlresponse *response;     nsdata *data = [nsurlconnection                     sendsynchronousrequest: request                     returningresponse: &response                     error: &myerror];        nslog(@"data %@",data);      nslog(@"response %@",response);      nsstring *result = [[nsstring alloc]initwithdata:data                                             encoding:nsutf8stringencoding];       nslog(@"result = %@",result);  } 

both data , response null. please me out in this. there changes need do? thank you.

your authentication string needs base64 encoded. try -

nsdata *userpassworddata = [[nsstring stringwithformat:@"%@:%@", username, password] datausingencoding:nsutf8stringencoding]; nsstring *base64encodedcredential = [userpassworddata base64encodedstringwithoptions:0]; nsstring *authheader= [nsstring stringwithformat:@"basic %@", base64encodedcredential]; nsmutableurlrequest *request = [nsmutableurlrequest requestwithurl: url                                                           cachepolicy: nsurlrequestreloadignoringcachedata                                                        timeoutinterval: 3];  [request addvalue:authheader forhttpheaderfield:@"authorization"]; 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -