我是IOS新手我使用POST方法创建了nsurlconnection我传递了参数" str"。在nslog str值变为null如何传递我的字符串" str"在post方法。
str编码: str字符串包含branchid1,currencyid1,currencyid2取自picker视图确实选择了行。
reconfig_view()
Picker视图编码:
str = [NSString stringWithFormat:@"branch_id=%@&from_curr=%@&to_curr=%@&value=%@",branchid1,currencyid1,currencyid2,fourthstr];
按钮操作:
- (void) pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
if(pickerView.tag ==2){
txtText.text = (NSString *)[arrMsg objectAtIndex:row];
branchid1 = (NSString *)[arrmsg1 objectAtIndex:row];
NSLog([arrmsg1 objectAtIndex:row]);
}else if(pickerView.tag ==1){
currency1.text = (NSString *)[currencyname1 objectAtIndex:row];
currencyid1 = (NSString *)[id1 objectAtIndex:row];
NSLog([id1 objectAtIndex:row]);
}
else
{
currency2.text = (NSString *)[from_currency objectAtIndex:row];
currencyid2 = (NSString *)[id2 objectAtIndex:row];
NSLog(@"%@",currencyid2);
NSLog([id2 objectAtIndex:row]);
}
发布方法:
}
按钮操作:
-(void) sendDataToServer : (NSString *) method params:(NSString *)str{
NSData *postData = [str dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[str length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:URL]];
NSLog(@"%@",str);
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody:postData];
NSURLConnection *theConnection = [NSURLConnection connectionWithRequest:request delegate:self];
if( theConnection ){
mutableData = [[NSMutableData alloc]init];
}
}