Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // WebserviceCall.m
- //
- //
- // Copyright (c) 2014 My Company. All rights reserved.
- //
- #import "WebserviceCall.h"
- #import "AFHTTPRequestOperationManager.h"
- AFHTTPRequestOperationManager *managerAF;
- @implementation WebserviceCall
- - (instancetype)init
- {
- self = [super init];
- if (self) {
- managerAF = [[AFHTTPRequestOperationManager alloc] init];
- }
- return self;
- }
- NSString *SSL_USERNAMEc=@"matest";
- NSString *SSL_PASSWORDc=@"kumar";
- -(void) authTockenCal
- {
- NSDictionary *params = @{
- @"grant_type": @"client_credentials"
- };
- //manager.requestSerializer = [AFJSONRequestSerializer serializer];
- [managerAF.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"];
- //[manager.requestSerializer setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"enctype"];
- [managerAF.requestSerializer setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
- [managerAF.requestSerializer setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"enctype"];
- [managerAF.requestSerializer setValue:[NSString stringWithFormat:@"Basic %@",[self base64forData:[[NSString stringWithFormat:@"%@:%@",SSL_USERNAMEc,SSL_PASSWORDc] dataUsingEncoding:NSUTF8StringEncoding]]] forHTTPHeaderField:@"Authorization"];
- //httpPost.setHeader("User-Agent", @"");
- //manager.appendPartWithFormData=postData;
- managerAF.responseSerializer = [AFHTTPResponseSerializer serializer];
- managerAF.securityPolicy.allowInvalidCertificates = YES;
- // manager.responseSerializer = [AFJSONResponseSerializer serializer]; // if response JSON format
- // [self.operationQueue addOperation:manager];
- [managerAF POST:@"https://example.com/stu/token" parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
- NSLog(@"JSON: %@", responseObject);
- NSHTTPURLResponse *response = (NSHTTPURLResponse *)operation.response;
- NSLog(@"Response: %@", operation.responseString);
- NSLog(@"%ld", (long)response.statusCode);
- NSData* data=[operation.responseString dataUsingEncoding:NSUTF8StringEncoding];
- NSString *response1 = [[NSString alloc] initWithBytes:[data bytes] length:[data length] encoding: NSUTF8StringEncoding];
- [self schoolPage];
- [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
- } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
- NSLog(@"Error: %@", operation.responseString);
- }];
- }
- -(void) schoolPage
- {
- //AFHTTPRequestOperationManager *managerAF = [AFHTTPRequestOperationManager manager];
- // AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
- [managerAF.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"];
- //[manager.requestSerializer setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"enctype"];
- [managerAF.requestSerializer setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
- [managerAF.requestSerializer setValue:@"sdsdsds-34343ndf-fdfd4545-45454545" forHTTPHeaderField:@"Authorization"];
- // Initialize Request Operation Manager
- managerAF.securityPolicy.allowInvalidCertificates = YES;
- // Configure Request Operation Manager
- [managerAF setResponseSerializer:[AFJSONResponseSerializer serializer]];
- [managerAF GET:@"https://exammple.com/std/groups/" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
- // Send Request
- NSLog(@"JSON: %@", responseObject);
- } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
- NSLog(@"Error: %@", operation.responseString);
- }];
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement