私は.Netソフトウェア開発者です。ユーザー検証用のWCFRestAPIを作成しました。以下はその署名です。
[OperationContract]
[WebInvoke(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "/Validate", Method = "POST")]
UserListResponse ValidateUser(Login obj);
次のリクエストボディでフィドラーで正常に動作しています
{"Username":"admin",Password:"111"}
私の問題は、http postメソッドを使用してiPhoneからアクセスできないことですが、AndroidHttppostメソッドでは正常に機能しています。
以下は私のコードです:
NSError *theError = nil;
NSArray *keys = [NSArray arrayWithObjects:@"Username", @"Password", nil];
NSArray *objects = [NSArray arrayWithObjects:@"admin", @"111", nil];
NSDictionary *jsonDictionary = [NSDictionary dictionaryWithObjects:objects forKeys:keys];
NSString *myJSONString =[jsonDictionary JSONRepresentation];
NSData *myJSONData =[myJSONString dataUsingEncoding:NSUTF8StringEncoding];
NSLog(@"myJSONString :%@", myJSONString);
NSLog(@"myJSONData :%@", myJSONData);
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://192.168.1.192/ShopMonkeyService/ShopMonkey.svc/Validate"]];
[request setHTTPBody:myJSONData];
[request setHTTPMethod:@"POST"];
NSURLResponse *theResponse =[[NSURLResponse alloc]init];
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&theResponse error:&theError];
NSLog(@"response : %@", theResponse);
NSLog(@"error : %@", theError);
NSLog(@"data : %@", data);
NSMutableString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"string: %@", string);
NSDictionary *jsonDictionaryResponse = [string JSONValue];
NSLog(@"dic: %@", jsonDictionaryResponse);
以下は私の応答エラーです:
2012-07-06 11:49:04.201 ShopMonkey [524:207]-JSONRepresentationが失敗しました。エラートレースは次のとおりです:(null)
2012-07-06 11:49:04.201 ShopMonkey [524:207] myJSONString:{"Password": "111"、 "Username": "admin"}
2012-07-06 11:49:04.201 ShopMonkey [524:207] myJSONData:<7b225061 7373776f 7264223a 22313131 222c2255 7365726e 616d6522 3a226164 6d696e22 7d>
2012-07-06 11:51:13.312 ShopMonkey [524:207]応答:( null)
2012-07-06 11:51:13.312 ShopMonkey [524:207]エラー:エラードメイン=NSURLErrorDomainコード=-1005「ネットワーク接続が失われました。」UserInfo = 0x6041370 {NSErrorFailingURLStringKey = http://192.168.1.192/ShopMonkeyService/ShopMonkey.svc/Validate、NSErrorFailingURLKey = http://192.168.1.192/ShopMonkeyService/ShopMonkey.svc/Validate、NSLocalizedDescription =ネットワーク接続が失われました。、NSUnderlyingError =0x6043a90"ネットワーク接続が失われました。"}
2012-07-06 11:51:13.312 ShopMonkey [524:207]データ:( null)
2012-07-06 11:51:13.313 ShopMonkey [524:207]文字列:
2012-07-06 11:51:13.313 ShopMonkey [524:207]-JSONValueが失敗しました。エラートレースは次のとおりです:(
"Error Domain=org.brautaset.JSON.ErrorDomain Code=11 \"Unexpected end of string\" UserInfo=0x6041b90 {NSLocalizedDescription=Unexpected
文字列の終わり}"
)。
2012-07-06 11:51:13.313 ShopMonkey [524:207] dic:(null)
誰かが私に何が悪いのか指摘できますか?
よろしくお願いしますvijay
エラーの詳細を見るvivek
エラーの詳細:
2012-07-06 16:54:37.416 ShopMonkey [1895:40b]-[CJSONSerializer serializeDictionary:]:認識されないセレクターがインスタンス0x4c03740に送信されました
2012-07-06 16:54:37.417 ShopMonkey [1895:40b] *キャッチされなかった例外'NSInvalidArgumentException'、理由:'-[CJSONSerializer serializeDictionary:]:認識されないセレクターがインスタンス0x4c03740に送信されたためにアプリを終了します
*最初のスローでスタックを呼び出す:
((
0 CoreFoundation 0x00ec2be9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x010175c2 objc_exception_throw + 47
2 CoreFoundation 0x00ec46fb-[NSObject(NSObject)doesNotRecognizeSelector:] + 187
3CoreFoundation0x00e34366転送+966
4 CoreFoundation 0x00e33f22 _CF_forwarding_prep_0 + 50
5 ShopMonkey 0x000030c5-[ShopMonkeyViewController signinbtnclick] + 425
6 UIKit 0x0034fa6e-[UIApplication sendAction:to:from:forEvent:] + 119
7 UIKit 0x003de1b5-[UIControl sendAction:to:forEvent:] + 67
8 UIKit 0x003e0647-[UIControl(Internal)_sendActionsForEvents:withEvent:] + 527
9 UIKit 0x003df1f4-[UIControl touchesEnded:withEvent:] + 458
10 UIKit 0x003740d1-[UIWindow _sendTouchesForEvent:] + 567
11 UIKit 0x0035537a-[UIApplication sendEvent:] + 447
12 UIKit 0x0035a732 _UIApplicationHandleEvent + 7576
13 GraphicsServices 0x0177ca36 PurpleEventCallback + 1550
14 CoreFoundation 0x00ea4064 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION + 52
15 CoreFoundation 0x00e046f7 __CFRunLoopDoSource1 + 215
16 CoreFoundation 0x00e01983 __CFRunLoopRun + 979
17 CoreFoundation 0x00e01240 CFRunLoopRunSpecific + 208
18 CoreFoundation 0x00e01161 CFRunLoopRunInMode + 97
19 GraphicsServices 0x0177b268 GSEventRunModal + 217
20 GraphicsServices 0x0177b32d GSEventRun + 115
21 UIKit 0x0035e42e UIApplicationMain + 1160
22ShopMonkey0x000026d8メイン+102
23ShopMonkey0x00002669開始+53
)。
'NSException'のインスタンスをスローした後に呼び出された終了