
[英]How to pass JSON data to another view controller from login function using post method?
[英]how to pass the custom headers and get the data from the server using post method (JSON)
根据你的形象
POST for posting data to SERVER
-(void)postDataToServer
{
//STEP 1 :Create the MutableURL Request
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://www.rgsgapp.com/api/debug/show"]];
//STEP 2 :create the Method "POST"
[request setHTTPMethod:@"POST"];
//STEP 3 :Pass The String to server(YOU SHOULD GIVE YOUR PARAMETERS INSTEAD OF MY PARAMETERS)
NSString *userUpdate =[NSString strin gWithFormat:@"API-ID=%@&API-TIME=%@API-HASH=%@",txtFldID.text,txtFldTime.text,txtFldHash.text,nil]; //Here you can give string or textField value
//STEP 4 :Check The Value what we passed
NSLog(@"the data Details is =%@", userUpdate);
//STEP 5 :Convert the String to Data
NSData *data1 = [userUpdate dataUsingEncoding:NSUTF8StringEncoding];
//STEP 6 :Apply the data to the body
[request setHTTPBody:data1];
//STEP 7 :Create the response and Error
NSError *err;
NSURLResponse *response;
//STEP 8 :send synchronous request to server
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
//STEP 9 :getting the response
NSString *resSrt = [[NSString alloc]initWithData:responseData encoding:NSASCIIStringEncoding];
//STEP 10:Check whether we got the Response or Not
NSLog(@"got response==%@", resSrt);
if(resSrt)
{
NSLog(@"got response");
}
else
{
NSLog(@"faield to connect");
}
}
在您的操作方法或您要执行的操作中调用上述方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.