我的客户获得了一项用于我注册的 Web 服务。我需要发布值。我正在使用以下代码发布:
-(IBAction)testingPurpose:(id)sender{
NSMutableDictionary *finalQuoteDict = [[NSMutableDictionary alloc] init];
[finalQuoteDict setValue:@"It is an Error Message" forKey:@"ErrorMsg"];
[finalQuoteDict setValue:@"json" forKey:@"ReturnVal"];
[finalQuoteDict setValue:@"john@live.com" forKey:@"Email"];
[finalQuoteDict setValue:@"David John" forKey:@"FullName"];
[finalQuoteDict setValue:@"2147483647" forKey:@"UserID"];
[finalQuoteDict setValue:@"john" forKey:@"UserName"];
[finalQuoteDict setValue:@"qqqqqq" forKey:@"UserPassword"];
SBJsonWriter *jsonWriter = [[SBJsonWriter alloc] init];
NSString *jsonRequest = [jsonWriter stringWithObject:finalQuoteDict];
jsonRequest = [jsonRequest stringByReplacingOccurrencesOfString:@"<" withString:@""];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@Register",MainUrl1,jsonRequest]];
NSLog(@"url is---%@",url);
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url
cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
NSData *requestData = [NSData dataWithBytes:[jsonRequest UTF8String] length:[jsonRequest length]];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setValue:[NSString stringWithFormat:@"%d", [requestData length]] forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody: requestData];
NSError* error = nil;
NSURLResponse* response;
NSData* result = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *dataString=[[NSString alloc]initWithData:result encoding:NSUTF8StringEncoding];
NSMutableDictionary *getResponseDict = [[NSMutableDictionary alloc] init];
[getResponseDict addEntriesFromDictionary:[dataString JSONValue]];
}
但它抛出一个错误说 “错误跟踪是:(“错误域=org.brautaset.JSON.ErrorDomain代码=3\”无法识别的前导字符\“用户信息=0x856ac50 {NSLocalizedDescription=无法识别的前导字符}”
请检查图像,即发布值..
我们是否需要提供请求类型“json/xml”
非常感谢提前