进出口新的IOS我有我想将数据发送到服务器并接收同样的方法响应如何将数据发送到服务器并接收同一methood响应
我有一个类名 profile.m疑问我想将数据发送到服务等级和接收型材类响应
Profile.m:
NSString *parameter = [NSString stringWithFormat:@"%@&access_token=%@&lksite=social&lkmenu=profile&lktype=view&displayedname=%@&displayid=%@", baseUrl, accessToken, userName,userId];
Service *service = [[Service alloc]init];
[service sendDataToServer:@"POST" andUrl:parameter andUrl:baseUrl];
Service.m
-(void) sendDataToServer:(NSString *) method andUrl:(NSString *) getUrl andUrl:(NSString *)baseUrl{
NSMutableData *jsondata;
Session *ses =[[Session alloc]init];
accessToken = [ses getAccessToken];
NSLog(@"Access Token---> %@",accessToken);
NSString *baseUrl1 = [NSString baseUrl];
if([method isEqualToString:@"GET"]){
NSString *urlStr = [NSString stringWithFormat: @"%@&access_token=%@",getUrl,accessToken];
url = [NSURL URLWithString: urlStr];
urlRequest= [NSMutableURLRequest requestWithURL:url];
urlRequest.HTTPMethod=method;
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self];
if(connection)
{
urlMutable = [NSMutableData new];
}
}else{
NSData *parameterData = [getUrl dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
url = [NSURL URLWithString: baseUrl1];
urlRequest=[NSMutableURLRequest requestWithURL:url];
urlRequest.HTTPBody=parameterData;
urlRequest.HTTPMethod=method;
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self];
if(connection)
{
urlMutable = [NSMutableData new];
}
}}
只需使用完成处理程序与块,第一个为成功,第二个为失败请求 –