0
我想從Objective-C和JSONKit發佈到rails後端,並且難以發佈我的結果。我不斷從我的服務器獲取空記錄集。Objective-C和JSONKit POST問題
[dictionary setValue:(@"bar") forKey:@"foo"];
NSString *JSON = [dictionary JSONString];
NSData *theData = [JSON dataUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString: myUrl];
NSString *postLength = [NSString stringWithFormat:@"%d", [theData length]];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
NSError *error = NULL;
NSURLResponse *response = nil;
[request setURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/json-rpc" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:theData];
NSData *result = [NSURLConnection sendSynchronousRequest:request
returningResponse:&response error:&error];
NSString *resultString = [[NSString alloc] initWithData:result encoding:NSUTF8StringEncoding];
NSLog(resultString);
有什麼我失蹤了嗎?在JSON似乎是正確的序列化
{「富」:「酒吧」}
任何幫助將不勝感激。
謝謝!
除了setValue中的括號(@「bar」),這不應該是問題,我在這裏沒有看到任何奇怪的東西。嘗試將請求的cachePolicy更改爲NSURLRequestReloadIgnoringCacheData,這可能會有所幫助。 – Davyd
謝謝,Davyd.i嘗試添加[request setCachePolicy:NSURLRequestReloadIgnoringCacheData];到上面,我仍然有問題。 – mat
服務器是否獲取您發送的數據? – Davyd