Skip to content Skip to sidebar Skip to footer

Getting Response Using "post" Method From .net Server(c# With Json Format) To Objective-c Issue

Hi I am a iOS Developer, Past 2 days onwards i am facing one issue like: In my .net developer provided me one API for getting response using POST method only not GET Step 1: Here i

Solution 1:

Solved. The api is misused. The data task should init with url request when using post method. HTTP body should store post data. By the way, you may need to disable app transport security in iOS9, if the server do not support https (https://gist.github.com/mlynch/284699d676fe9ed0abfa).

-(void)getUserNameStr: (NSString*)newUsername withPassword: (NSString*)newPassword{
    NSString*urlStr = @"http://taxi.expertverification.com/api/v1/ValidUser";
    NSString * myRequestString =[NSString stringWithFormat:@"UserName=%@&Password=%@",
                                 newUsername,
                                 newPassword];
    NSData *myRequestData = [NSData dataWithBytes: [myRequestString UTF8String] length: [myRequestString length]];
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:urlStr]];
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"];
    [request setHTTPMethod: @"POST"];
    //post section
    [request setHTTPBody: myRequestData];
    NSURLSession *session = [NSURLSession sharedSession];
    [[session dataTaskWithRequest:request
                completionHandler:^(NSData *data,
                                    NSURLResponse *response,
                                    NSError *error) {
                    // handle response
                    NSString *requestReply = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
                    NSLog(@"requestReply: %@", requestReply);

                }] resume];
}

Post a Comment for "Getting Response Using "post" Method From .net Server(c# With Json Format) To Objective-c Issue"