simona milcevska simona milcevska - 5 months ago 41
Objective-C Question

POST JSON data from iOS to mssql Server

Can someone please tell me what is the best way to create web service that sends JSON to MS SQL server.(php or .net POST web service?)
I want to host the web service on IIS if possible.Links of tutorials will be very useful.
Many Thanks.

Answer
//Create the request

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"your script name.php"]];
// create the Method "GET" or "POST"

[request setHTTPMethod:@"POST"];

   //Pass The String to server
NSString *userUpdate =[NSString stringWithFormat:@"artist_email=%@ ",your string Name,nil];

//Check The Value what we passed
NSLog(@"the data Details is =%@", userUpdate);

//Convert the String to Data
NSData *data1 = [userUpdate dataUsingEncoding:NSUTF8StringEncoding];

//Apply the data to the body
[request setHTTPBody:data1];

//Create the response and Error

NSError *err;
NSURLResponse *response;

NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];

NSString *resSrt = [[NSString alloc]initWithData:responseData encoding:NSASCIIStringEncoding];

//This is for Response 
NSLog(@"got response==%@", resSrt);

if(resSrt)
{
    NSLog(@"got response");


}
else
{
    NSLog(@"faield to connect");
}
Comments