tian-sun

post同步请求

// http://api.hudong.com/iphonexml.do?type=focus-c
    //post请求中url不带请求参数,请求参数在参数HTTPBody中设置, 需要创建可变的url请求,设置请求方式为post        
//创建url
    NSURL *url = [[NSURL alloc] initWithString:@"http://api.hudong.com/iphonexml.do"];
        //创建可变的url请求
    NSMutableURLRequest *mRequest = [[NSMutableURLRequest alloc] initWithURL:url];
        //设置请求方式为POST
    mRequest.HTTPMethod = @"POST";
        //设置请求参数
    NSString *sendString = @"type=focus-c”;
        //HTTPBodyNSData类型, 所以需要将NSString类型转换为NSDate类型
    mRequest.HTTPBody = [sendString dataUsingEncoding:NSUTF8StringEncoding];
    
        //发送同步请求
    NSData *data = [NSURLConnection sendSynchronousRequest:mRequest returningResponse:nil error:nil];
        //NSData转换为NSString类型
    NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    NSLog(@"%@", string);

 

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-07
  • 2022-12-23
猜你喜欢
  • 2021-06-04
  • 2021-11-07
  • 2022-12-23
  • 2021-07-13
相关资源
相似解决方案