1

Here's the code snippet I'm working on:

    NSError *error = nil;
    NSData *data = [NSJSONSerialization dataWithJSONObject:body options:0 error:&error];
    NSString *string = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];

    [request setValue:[[NSString alloc] initWithFormat:@"%d", string.length] forHTTPHeaderField:@"Content-Length"];
    [request setValue:string forHTTPHeaderField:@"json"];
    [request setHTTPBody:data];

    NSLog(@"request.values: %@", [request allHTTPHeaderFields]);

The NSLog returns only the first value:header (i.e. "Content-Length" = 74288), but does not show anything for the value:header containing my string property. I've checked that string exists, it's just really long. My guess is that it's the length of the value field that is causing it not to be set to the header. That, or my JSON format is weird (it's a dictionary containing an array of dictionaries).

Any thoughts?0

ebandersen
  • 2,362
  • 26
  • 25
  • Why would you need to put JSON string to header? I assume it is a POST request, so you would actually need to do something similar to what is described in this answer http://stackoverflow.com/a/14551320/737347 – ivanmoskalev Aug 07 '13 at 20:24
  • I was experimenting passing the json in the header because the WCF web service I'm connecting with (not controlled by me) is unable to deserialize the body of my request. Thanks for the link though! I'll take a look into it right away. – ebandersen Aug 07 '13 at 21:10

0 Answers0