Object-c http get请求

//加载服务器指定地址的URL:configURL带上projectId

NSString *requestUrl = [NSString stringWithFormat:@"%@/%@",configURL,projectId];

NSLog(@"requestUrl= %@",requestUrl);

  //同步执行Http请求,获取返回数据

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:requestUrl]];

NSError *requestError ;

NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&requestError];

  //(如果有错误)错误描述

if (requestError!=nil) {

NSLog(@"requestError=%@",requestError);

}

NSLog(@"returnData=%@",returnData);

 //返数据转成字符串

NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];

NSLog(@"returnString=%@",returnString);

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容