Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2014
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.82 KB | None | 0 0
  1. //
  2. // WebserviceCall.m
  3. //
  4. //
  5. // Copyright (c) 2014 My Company. All rights reserved.
  6. //
  7.  
  8. #import "WebserviceCall.h"
  9.  
  10. #import "AFHTTPRequestOperationManager.h"
  11.  
  12. AFHTTPRequestOperationManager *managerAF;
  13. @implementation WebserviceCall
  14.  
  15.  
  16. - (instancetype)init
  17. {
  18. self = [super init];
  19. if (self) {
  20. managerAF = [[AFHTTPRequestOperationManager alloc] init];
  21. }
  22. return self;
  23. }
  24.  
  25. NSString *SSL_USERNAMEc=@"matest";
  26. NSString *SSL_PASSWORDc=@"kumar";
  27.  
  28.  
  29. -(void) authTockenCal
  30. {
  31.  
  32.  
  33.  
  34. NSDictionary *params = @{
  35. @"grant_type": @"client_credentials"
  36. };
  37. //manager.requestSerializer = [AFJSONRequestSerializer serializer];
  38. [managerAF.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"];
  39. //[manager.requestSerializer setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"enctype"];
  40. [managerAF.requestSerializer setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
  41. [managerAF.requestSerializer setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"enctype"];
  42.  
  43. [managerAF.requestSerializer setValue:[NSString stringWithFormat:@"Basic %@",[self base64forData:[[NSString stringWithFormat:@"%@:%@",SSL_USERNAMEc,SSL_PASSWORDc] dataUsingEncoding:NSUTF8StringEncoding]]] forHTTPHeaderField:@"Authorization"];
  44. //httpPost.setHeader("User-Agent", @"");
  45.  
  46. //manager.appendPartWithFormData=postData;
  47. managerAF.responseSerializer = [AFHTTPResponseSerializer serializer];
  48. managerAF.securityPolicy.allowInvalidCertificates = YES;
  49. // manager.responseSerializer = [AFJSONResponseSerializer serializer]; // if response JSON format
  50. // [self.operationQueue addOperation:manager];
  51. [managerAF POST:@"https://example.com/stu/token" parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
  52.  
  53.  
  54.  
  55. NSLog(@"JSON: %@", responseObject);
  56. NSHTTPURLResponse *response = (NSHTTPURLResponse *)operation.response;
  57. NSLog(@"Response: %@", operation.responseString);
  58.  
  59. NSLog(@"%ld", (long)response.statusCode);
  60.  
  61. NSData* data=[operation.responseString dataUsingEncoding:NSUTF8StringEncoding];
  62.  
  63. NSString *response1 = [[NSString alloc] initWithBytes:[data bytes] length:[data length] encoding: NSUTF8StringEncoding];
  64.  
  65.  
  66.  
  67. [self schoolPage];
  68. [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
  69.  
  70.  
  71.  
  72. } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
  73. NSLog(@"Error: %@", operation.responseString);
  74.  
  75.  
  76. }];
  77. }
  78.  
  79.  
  80. -(void) schoolPage
  81. {
  82. //AFHTTPRequestOperationManager *managerAF = [AFHTTPRequestOperationManager manager];
  83. // AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
  84.  
  85. [managerAF.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"];
  86. //[manager.requestSerializer setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"enctype"];
  87. [managerAF.requestSerializer setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
  88.  
  89. [managerAF.requestSerializer setValue:@"sdsdsds-34343ndf-fdfd4545-45454545" forHTTPHeaderField:@"Authorization"];
  90.  
  91.  
  92. // Initialize Request Operation Manager
  93. managerAF.securityPolicy.allowInvalidCertificates = YES;
  94.  
  95. // Configure Request Operation Manager
  96. [managerAF setResponseSerializer:[AFJSONResponseSerializer serializer]];
  97.  
  98. [managerAF GET:@"https://exammple.com/std/groups/" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
  99.  
  100. // Send Request
  101. NSLog(@"JSON: %@", responseObject);
  102.  
  103.  
  104. } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
  105. NSLog(@"Error: %@", operation.responseString);
  106.  
  107. }];
  108. }
  109.  
  110.  
  111. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement