【问题标题】:ASIFormDataRequest post method is not working in iosASIFormDataRequest post方法在ios中不起作用
【发布时间】:2015-10-06 11:35:13
【问题描述】:

嗨,我是 Ios 的初学者,在我的项目中为用户“ForGotPassword”请求提供了便利

为此,我编写了一些代码,但不起作用

即 objectFromJSONString 响应显示为 -->Message: "No HTTP resource was found that match the request URI "my url."

我在这里做错了什么,是我的问题还是服务器端的问题?请帮帮我

我的代码:-

  - (IBAction)submitBtnClicked:(id)sender {


        NSLog(@"password ---->>> %@",self.MedicalIdTxt.text);

        NSString *urlStr = [NSString stringWithFormat:@"my url"];

        NSLog(@"urlStr --->>> %@",urlStr);

        ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:urlStr]];

        [request setRequestMethod:@"POST"];

        [request setPostValue:self.MedicalIdTxt.text forKey:@"MedicaidId"];

        [request setDelegate:self];

        [request startAsynchronous];

        [MBProgressHUD showHUDAddedTo:self.view animated:YES];

    }

    - (void)requestFinished:(ASIHTTPRequest *)request {

        NSLog(@"requestFinished");

        [MBProgressHUD hideHUDForView:self.view animated:YES];

        NSLog(@"%@",request);
        NSString *receivedString = [request responseString];

        NSLog(@"receivedString %@",receivedString);

        NSDictionary * jsonObj=[[NSDictionary alloc]init];

        jsonObj = [receivedString objectFromJSONString];

        NSLog(@"jsonObj result is%@",jsonObj);

        NSString *messageStr = [jsonObj objectForKey:@"message"];

        UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"" message:messageStr delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
        [alertView show];


    }

    - (void)requestFailed:(ASIHTTPRequest *)request {

        [MBProgressHUD hideHUDForView:self.view animated:YES];

        NSString *receivedString = [request responseString];

         UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:receivedString message:@"" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
          [alertView show];

    }

这里的“jsonObj”没有显示来自服务的响应我在这里做错了什么?

【问题讨论】:

  • 您使用的是哪个 Xcode 版本?
  • 我使用的是 6.4 版
  • 如果您使用相同的鳕鱼,那么它在 NSString *urlStr = [NSString stringWithFormat:@"my url"]; 中的错误您应该使用您的域网址而不是 @"my url"。
  • 看不懂请解释清楚
  • 请注意ASIHTTPRequest 已不再开发,现在在 iOS 6 及更高版本中存在错误。我建议你搬到另一个图书馆,比如AFNetworking

标签: ios objective-c


【解决方案1】:

ASIHTTPRequest 很久没有维护了,所以改用AFNetworking

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager POST:@"your url"
       parameters:@{@"color": @"green"}
          success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSLog(@"JSON: %@", responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"Error: %@", error);
    }];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-06-06
    • 2017-01-28
    • 1970-01-01
    • 1970-01-01
    • 2023-04-04
    • 1970-01-01
    • 2018-02-21
    相关资源
    最近更新 更多