I've been searching for hours to a solution to this problem, and I can find nothing that solves my issue. I receive Invalid JSON Primitive
whenever I attempt to send a URL with a string value (NSString) in it to my server via an HTTP Get.
My code:
Client Side Obj-C
- (void) createRequest: (NSString*)urlFormatted {
NSURL *url = [NSURL URLWithString: urlFormatted];
NSMutableURLRequest *request =[NSMutableURLRequest requestWithURL: url];
[request setHTTPMethod:@"GET"];
[request setValue:@"application/json; charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
_webData = [[NSMutableData data] retain];
_connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
}
-(void) authenticate:(NSString*) userName password:(NSString*)password
{
NSString*url = @"http://service.example.com/service.asmx/Test?test1=hi";
[self createRequest:url];
[url release];
}
Server Side C#
This does not work. Whenever I have a string as a parameter, I receive the message,
Invalid JSON Primitive
e.g.
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public string Test(string test1)
{
return "Ok."; // For testing purposes, just return a string.
}
This however, works fine. (Obviously if I change my test1 parm to an integer)
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public string Test(int test1)
{
return "Ok."; // For testing purposes, just return a string.
}
Everything I have read points me to ensure that I have application/json
set - which it is. Whenever I don't use strings in my URL, everything is fine. I don't understand why this doesn't work. It doesn't looking like an encoding issue to me. Any ideas?