I am passing parameters to a REST web service and it keeps saying:
The server refused this request because the request entity is in a format
not supported by the requested resource for the requested method
I create a NSDictionary like this with all my parameters:
NSMutableDictionary *webServiceParameters;
webServiceParameters = [[NSMutableDictionary alloc] init];
[webServiceParameters setObject:mytextbox.text forKey:@"value1"];
Then I pass it into the request:
NSURL *url = [NSURL URLWithString:webServiceURL];
AFHTTPClient *client = [[AFHTTPClient alloc] initWithBaseURL:url];
NSURLRequest *myRequest = [client requestWithMethod:@"POST" path:@"" parameters:webServiceParameters];
client.parameterEncoding = AFJSONParameterEncoding;
NSLog(@"%@", myRequest);
AFJSONRequestOperation *operation;
operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:myRequest
success:^(NSURLRequest *request, NSHTTPURLResponse *response, NSDictionary *JSON)
{
}
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, NSArray *JSON)
{
NSLog(@"%@", [error userInfo]);
}
];
[operation start];
My assumption is that the :
client.parameterEncoding = AFJSONParameterEncoding;
would turn the parameters into a JSON request but its not changing the header file. I couldnt figure out a way to change the header file on this. All the documentation on AFNetworking is now in 2.0 and I still have to use 1.X.. How can I pass a value in the header to tell it that its application/json and will that parameterEncoding actually pass it as JSON?
I have tried: [myRequest setValue:@"" forHTTPHeaderField:@""];
but the compiler throws this error:
No visible interface for NSUrlRequest declares the selector setValue: for HTTPHeaderField