Advertisement
Guest User

Untitled

a guest
Jan 10th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. -(void)getUserNameStr: (NSString*)newUsername withPassword: (NSString*)newPassword{
  2. NSString*urlStr = @"http://taxi.expertverification.com/api/v1/ValidUser?";
  3. NSString * myRequestString =[NSString stringWithFormat:@"%@UserName=%@&Password=%@",
  4. urlStr,
  5. newUsername,
  6. newPassword];
  7. NSData *myRequestData = [NSData dataWithBytes: [myRequestString UTF8String] length: [myRequestString length]];
  8. NSMutableURLRequest *request = [[NSMutableURLRequest alloc]init];
  9. [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"];
  10. [request setHTTPMethod: @"POST"];
  11. //post section
  12. [request setHTTPBody: myRequestData];
  13. NSURLSession *session = [NSURLSession sharedSession];
  14. [[session dataTaskWithURL:[NSURL URLWithString:myRequestString]
  15. completionHandler:^(NSData *data,
  16. NSURLResponse *response,
  17. NSError *error) {
  18. // handle response
  19. NSString *requestReply = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
  20. NSLog(@"requestReply: %@", requestReply);
  21.  
  22. }] resume];
  23. }
  24.  
  25. requestReply: {"Message":"The requested resource does not support http method 'GET'."}
  26.  
  27. ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
  28. Log.d(TAG, "ba1: "+ba1);
  29.  
  30.  
  31. nameValuePairs.add(new BasicNameValuePair("UserName", "rkb");
  32. nameValuePairs.add(new BasicNameValuePair("Password", "rkb");
  33.  
  34.  
  35.  
  36. try{
  37. HttpClient httpclient = new DefaultHttpClient();
  38.  
  39. HttpPost httppost = new HttpPost("http://taxi.expertverification.com/api/v1/ValidUser?";
  40.  
  41. httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
  42.  
  43. HttpResponse response = httpclient.execute(httppost);
  44. HttpEntity entity = response.getEntity();
  45.  
  46. String outPut = EntityUtils.toString(entity);
  47. Log.i("GET RESPONSE—-", outPut);
  48.  
  49. Log.e("log_tag ******", "good connection";
  50.  
  51. bitmapOrg.recycle();
  52. }catch (Exception e) {
  53. Log.e("log_tag ******", "Error in http connection " + e.toString());
  54. }
  55.  
  56. true
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement