0

I have to pass data like json format to the server

{"email":"[email protected]","password":"abc"}

and i have used this code but data is not pass to the server please help me..

    NSDictionary *dict1=@{@"email": @"[email protected]"};
    NSDictionary *dict2=@{@"password": @"biren"};
    services *srv=[[services alloc]init];

    NSString *str=@"http://emailsending.in/setting_saver_api/";
    NSString *method=@"login.php";
    NSMutableDictionary *dict=[[NSMutableDictionary alloc]init];

    [dict setValue:dict1 forKey:@"email"];

    [dict setValue:dict2 forKey:@"password"];


    [srv postToURL:str withMethod:method andParams:dict completion:^(BOOL success, NSDictionary *responseObj)

     {
         NSLog(@"res :%@",responseObj);
         NSLog(@"%d",success);

         NSLog(@"Successfully..................");


     }];

3 Answers 3

1

you can check your link at https://www.hurl.it/

1)give your http link

2)select your method type "Get" or "Post"

3)add the parameters

and check the response.If you get the same response contact your backend team.

Sign up to request clarification or add additional context in comments.

6 Comments

how to send json parameter in hurl?
A JSON object of name/value attribute pairs. The attribute name is used for the parameter name. The attribute value should be an array of values. If you need to specify multiple parameters with the same name but different values, specify the name once and pass the values into the array.Only used if method specified is POST, PUT, PATCH or DELETE. For example, {"name":["John"]} or {"name":["John", "Frank"]}. Try It
i give you link,method and parameter in my question so give me the full link so i can test else you test and give me the response because i dont understand how to pass parameter in hurl
{"status":"0","msg":"Data is required"},this response is coming.Contact your backend team
ok thanks i get same response in my code so there is error in my code side?
|
0

Try this. 1) Convert your dictionary into json using NSJSONSerialization and store it in NSdata.

NSData * incidentData = [NSJSONSerialization dataWithJSONObject: params options:0 error:&err];

2) Post the NSdata containing json to your server

1 Comment

hi you can edited my above code so i better understand
0

Try this,if this helps

  NSString *str = @"http://emailsending.in/setting_saver_api/"; 

NSString*method = @"login.php";

    services *srv=[[services alloc]init];

    NSMutableDictionary *dict1 = [NSMutableDictionary dictionary]; [dict1 setValue:@"[email protected]" forKey:@"email"];

    NSMutableDictionary *dict2 = [NSMutableDictionary dictionary]; [dict2 setValue:@"biren" forKey:@"password"];


    NSMutableDictionary *dict=[[NSMutableDictionary alloc]init];

        [dict setValue:dict1 forKey:@"email"];

        [dict setValue:dict2 forKey:@"password"];

    AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc] initWithBaseURL:baseURL]; manager.requestSerializer = [AFJSONRequestSerializer serializer]; manager.responseSerializer = [AFJSONResponseSerializer serializer];

    [manager POST:str parameters:dict success:^(NSURLSessionDataTask
    *task, id responseObject) {

            NSLog(@"JSON: %@", responseObject);
            //here is place for code executed in success case

    } failure:^(NSURLSessionDataTask *task, NSError *error) {

            //here is place for code executed in error case
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error while sending POST"
                                                                message:@"Sorry, try again."
                                                               delegate:nil
                                                      cancelButtonTitle:@"Ok"
                                                      otherButtonTitles:nil];
            [alertView show];

            NSLog(@"Error: %@", [error localizedDescription]); }];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.