I am new to IOS i created nsurlconnection using POST method i passed a parameter "str".In nslog str value become null how to pass my string "str" in post method.
str coding: str string contain branchid1,currencyid1,currencyid2 are taken from picker view did select row.
str = [NSString stringWithFormat:@"branch_id=%@&from_curr=%@&to_curr=%@&value=%@",branchid1,currencyid1,currencyid2,fourthstr];
Picker view coding:
- (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]);
}
button action:
}
post method:
-(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];
}
}
button action:
- (IBAction)btnact:(id)sender {
if (branchides.length!=0 && currencyide1.length!=0 && currencyid2.length!=0 && fourthstr.length!=0)
{
str = [NSString stringWithFormat:@"branch_id=%@&from_curr=%@&to_curr=%@&value=%@",branchides,currencyide1,currencyid2,fourthstr];
NSLog(@"%@",str);
//[self sendDataToServer :@"POST" params:str];
}
else
{
// show some alert for empty
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Value"
message:final
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"ok", nil];
alert.tag = 100;
[alert show];
[self sendDataToServer :@"POST" params:str];
}