//第一步,创建URL 

NSURL *urls = [NSURLURLWithString:url];

url  为请求链接

//    //第二步,创建请求

NSMutableURLRequest*request= [[NSMutableURLRequestalloc]initWithURL:urls cachePolicy:NSURLRequestUseProtocolCachePolicytimeoutInterval:10];

[request setHTTPMethod:@"POST"];//设置请求方式为POST,默认为GET

NSString *str = [NSStringstringWithFormat:@"usere=%@&pwd=%@",zhStr,mmStr];//设置参数 

    NSData *data = [str dataUsingEncoding:NSUTF8StringEncoding];

    [request setHTTPBody:data];

//    //第三步,连接服务器

    NSData *received = [NSURLConnectionsendSynchronousRequest:request returningResponse:nilerror:nil];

//转换格式NSString//    

NSString *str1 = [[NSStringalloc]initWithData:received encoding:NSUTF8StringEncoding];

//   转换格式NSDictionary

NSDictionary*jsonDict=[NSJSONSerializationJSONObjectWithData:receivedoptions:NSJSONReadingMutableLeaveserror:nil];

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐