0

I am developing an application with REST full web service .Now i have some problem in this case ,ie string sent to a servier using put method. I am using the following code.

NSMutableURLRequest* request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://176.31.113.164/app/profil/add"]];
    [request setValue:@"Digest adf@email.com:test" forHTTPHeaderField:@"Authorization"];
     [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
     [request setValue:@"application/json" forHTTPHeaderField:@"content-type"];
    //[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    NSDictionary *dic=[[NSDictionary alloc]init ];
        dic=[NSDictionary dictionaryWithObjectsAndKeys:@"15",@"@idUsers",@"17",@"@idProfils",@"ddduu",@"address",@"ddd",@"city",@"ddd",@"country",@"adf@email.com <mailto:adf@email.com>",@"email",@"1",@"enabled",@"fff55",@"firstName",@"fffdd3",@"lastName",@"fffffcc",@"nickName",@"test",@"password",@"0",@"phone",@"0",@"postCode",@"ROLE_USER",@"role", nil];
    NSString *jsonString = [jsonWriter stringWithObject:dic];
     NSData *postData= [jsonString dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:NO];
     [request setHTTPBody:postData];
        [request setHTTPMethod:@"PUT"];
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];

        NSURLConnection* _loginConnection=[[NSURLConnection alloc] initWithRequest:request delegate:self];
     if (_loginConnection==NULL)
        {
            NSLog(@"Problem");
        }
    [_loginConnection start];

The received data is handled as this:

NSString* tempString =[NSJSONSerialization 
                  JSONObjectWithData:_receivedData 

                  options:kNilOptions 
                  error:&error];
John
  • 734
  • 3
  • 14
  • 30

1 Answers1

0

You can use ASIHTTP wrapper class to perform REST operations in your iOS application.

Download the latest ASIHTTP from here.

sunhsiv
  • 311
  • 1
  • 7