1

enter image description here . THIS is PLIST

 NSString *post = [NSString stringWithFormat:@"email=%@&password=%@ & user_type=%@",_emailID.text,_password.text, user_type];
    NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
    NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[postData length]];
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
    [request setURL:[NSURL URLWithString:@"my url"]];
    [request setHTTPMethod:@"POST"];
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    [request setHTTPBody:postData];

    NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];

    if(conn) {
        NSLog(@"Connection Successful");
    } else {
        NSLog(@"Connection could not be made");
    }

}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData*)data{
    [self.receivedData appendData:data];

}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{
    NSLog(@"%@" , error);

}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection{

    NSLog(@"Connected %@",connection); 
}

I'm using this code in my Login form to POST data from email and password fields. i'm facing an error and not getting any response. Error is:

2017-05-01 10:58:06.236 PK.Estate[13412:4023436] App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file. 2017-05-01 10:58:06.397 PK.Estate[13412:4022282] Error Domain=NSURLErrorDomain Code=-1022 "The resource could not be loaded because the App Transport Security policy requires the use of a secure connection." UserInfo={NSUnderlyingError=0x608000253260 {Error Domain=kCFErrorDomainCFNetwork Code=-1022 "The resource could not be loaded because the App Transport Security policy requires the use of a secure connection." UserInfo={NSErrorFailingURLStringKey=url, NSLocalizedDescription=The resource could not be loaded because the App Transport Security policy requires the use of a secure connection., NSErrorFailingURLKey=url}}, NSErrorFailingURLStringKey=url, NSErrorFailingURLKey=url, NSLocalizedDescription=The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.}

Fahim Parkar
  • 30,974
  • 45
  • 160
  • 276
Hamza Imran
  • 55
  • 1
  • 7
  • 1
    You should use HTTPS exclusively. If you must use http then see here: http://stackoverflow.com/questions/32631184/the-resource-could-not-be-loaded-because-the-app-transport-security-policy-requi for how to do it. – Jon Rose May 01 '17 at 10:49
  • i know there r much more answers on satck overflow and other site i have applied them nut the issue is still there – Hamza Imran May 01 '17 at 10:49
  • i have tried this link also but not working its about 4 days the problem is still there. @JonRose – Hamza Imran May 01 '17 at 10:53
  • isn't `email=%@&password=%@ & user_type=%@` should be `email=%@&password=%@&user_type=%@` there is space before user_type & after password – Fahim Parkar May 01 '17 at 10:54
  • try to add in your plist file : You have to add just the NSAllowsArbitraryLoads key to YES in NSAppTransportSecurity dictionary in your info.plist file. For example, NSAppTransportSecurity NSAllowsArbitraryLoads – KKRocks May 01 '17 at 10:55
  • Domain=NSURLErrorDomain Code=-1002 "unsupported URL" UserInfo={NSLocalizedDescription=unsupported URL, NSUnderlyingError=0x60000005f020 {Error Domain=kCFErrorDomainCFNetwork Code=-1002 "unsupported URL" UserInfo={NSLocalizedDescription=unsupported URL}}} this error . @FahimParkar – Hamza Imran May 01 '17 at 11:09
  • i have done that before but same error man. @KKRocks – Hamza Imran May 01 '17 at 11:10
  • in which plist ..there are many plist file in project. – KKRocks May 01 '17 at 11:15
  • i didn't understand? @KKRocks – Hamza Imran May 01 '17 at 11:39
  • Im using Xcode 8 and IOS9 – Hamza Imran May 01 '17 at 11:40
  • did you added this in plist....? – KKRocks May 01 '17 at 11:40
  • yes i have added that. @KKRocks – Hamza Imran May 01 '17 at 11:47
  • ok then in which plist that you need to cross check – KKRocks May 01 '17 at 11:49
  • im not familiar with that error I'm doing this for first time can u explain what r u saying. @KKRocks – Hamza Imran May 01 '17 at 11:52
  • try this steps : http://stackoverflow.com/a/32817873/3901620 – KKRocks May 01 '17 at 11:57
  • in a link where there is written in a bracket (1 item) when is do this in my plist there is written (0 item). how it can be change to 1. @KKRocks – Hamza Imran May 01 '17 at 12:02
  • 1
    if not sure first take backup then remove all your added line from plist which are you have recently add. and follow steps : ** right click on plist > open as source code**. and add on top this line NSAppTransportSecurity NSAllowsArbitraryLoads – KKRocks May 01 '17 at 12:04
  • did you try with `password=%@&user_type=%@` as there are spaces in your code? your code says `password=%@ & user_type=%@` – Fahim Parkar May 01 '17 at 13:44
  • no there is no space . @FahimParkar – Hamza Imran May 01 '17 at 13:53

1 Answers1

0

I think you are using http in your url url. If you are using this make changes in plist enter image description here

Vinay Kumar
  • 107
  • 1
  • 12
  • when i write App Transport Security Settings to dictionary it shows me 0items in a bracket. @Vinay Kumar – Hamza Imran May 01 '17 at 11:35
  • Please add App Tranport Security first and then click on drop down on the left most side off App Transport. Then click on plus button and then add "Allow Arbitrary Loads" – Vinay Kumar May 01 '17 at 12:02
  • If sitting facing issue please edit your question and screen shot of your Info.plist page – Vinay Kumar May 01 '17 at 12:03
  • it first show message "Connection Successful" and then shows same error. @Vinay Kumar – Hamza Imran May 01 '17 at 12:07
  • Please add screen shot of your plist – Vinay Kumar May 01 '17 at 12:09
  • Error Domain=NSURLErrorDomain Code=-1002 "unsupported URL" UserInfo={NSLocalizedDescription=unsupported URL, NSUnderlyingError=0x60800024c1b0 {Error Domain=kCFErrorDomainCFNetwork Code=-1002 "unsupported URL" UserInfo={NSLocalizedDescription=unsupported URL}}} again same error. @Vinay Kumar – Hamza Imran May 01 '17 at 12:19
  • i have added above in a question check that out. @Vinay Kumar – Hamza Imran May 01 '17 at 12:21
  • As I am seeing in you screen shot Allow Arbitrary Loads is out side App Transport security. Please on drop down on the left side of the App Tranport Security and then click on plus btn on right of the App Transport Security. Please look care fully in my screen shot. – Vinay Kumar May 01 '17 at 12:49
  • App Transport Security showing 1 dictionary item or not? – Vinay Kumar May 01 '17 at 13:04
  • check the edited question i have added screen shot. @Vinay Kumar – Hamza Imran May 01 '17 at 13:11
  • @HamzaImran Please check my screen shot care fully. I have used App Transport Security not NSAppTransport – Vinay Kumar May 01 '17 at 13:19
  • Error Domain=NSURLErrorDomain Code=-1002 "unsupported URL" UserInfo={NSLocalizedDescription=unsupported URL, NSUnderlyingError=0x60800024de60 {Error Domain=kCFErrorDomainCFNetwork Code=-1002 "unsupported URL" UserInfo={NSLocalizedDescription=unsupported URL}}} error again . @Vinay Kumar – Hamza Imran May 01 '17 at 13:28
  • have u find any solution? @Vinay Kumar – Hamza Imran May 02 '17 at 05:18