私のクライアントには、私の登録用に 1 つの 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]];
}
しかし、 「エラー トレースは: ( "Error Domain=org.brautaset.JSON.ErrorDomain Code=3 \"認識されない先頭文字\" UserInfo=0x856ac50 {NSLocalizedDescription=認識されない先頭文字}」というエラーがスローされます。
値を投稿するには、画像を確認してください..
リクエスト タイプに「json/xml」のいずれかを指定する必要がありますか
事前にどうもありがとう