進出口新的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];
}
}}
只需使用完成處理程序與塊,第一個爲成功,第二個爲失敗請求 –