获取错误域= kCFErrorDomainCFNetwork代码= -1000或NSCocoaErrorDomain代码= 3840

时间:2014-02-06 08:11:11

标签: ios iphone objective-c ipad nsurlconnection

首先,我想告诉你一个重复的问题,但我已经尝试了所有可能的方法 - 我搜索过的链接 - > Bad URL when requesting with NSURL

iOS Develoment: Why is my NSURLConnection failing with a "bad URL" error for only some users? Bad URL when requesting with NSURL

我正在向服务器发送请求 - >但是总是得到错误的网址错误,即

Request Failed with Error: Error Domain=NSURLErrorDomain Code=-1000 "bad URL" UserInfo=0xcbf0680 {NSUnderlyingError=0xc9ad8e0 "bad URL", NSLocalizedDescription=bad URL}, {
    NSLocalizedDescription = "bad URL";
    NSUnderlyingError = "Error Domain=kCFErrorDomainCFNetwork Code=-1000 \"bad URL\" UserInfo=0xc96dc30 {NSLocalizedDescription=bad URL}";
}

代码 - >

 NSString *imgUrl = [NSString stringWithFormat:@"https://graph.facebook.com/%@/picture", fbid];




                NSString *urlString = [NSString stringWithFormat:@"%@url=register_user.json&username=%@&email=%@&dob=%@&by_socialnetwork=\"1\"&gender=%@&nicename=%@&socialimageurl=%@",BASE_URL,[info_dict objectForKey:@"username"],[info_dict objectForKey:@"email"],[info_dict objectForKey:@"birthday"],[info_dict objectForKey:@"gender"],[info_dict objectForKey:@"name"],imgUrl];

                 NSLog(@"url  %@",urlString );
                 [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:urlString] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:5.0];
                    [request setHTTPMethod:@"GET"];
                    [request addValue:@"text/json; charset=utf-8" forHTTPHeaderField:@"Content-Type"];


                 //NSURLRequest *request=[[NSURLRequest alloc] initWithURL:[NSURL URLWithString:urlString]];

                 NSLog(@"url  %@",request );
                 AFJSONRequestOperation *operation=[AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
                     NSLog(@"dgj,gfj,gf,j%@",JSON);
                     [self requestSucceedWithItems:JSON forRequestType:@"FB"];

                 }failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {

                     NSLog(@"Request Failed with Error: %@, %@", error, error.userInfo);
                     [appdelegate showAlert:@"Error" forText:@"Network activity failed,Try later."];

                 }];

                 [operation start];

终端NSLOG响应: -

 url  <NSURLRequest: 0xcd8d060> { URL: http://192.168.1.100/~ha/gokk/index.php?url=register_user.json&username=abx&email=abxx@gmail.com&dob=12/19/1978&by_socialnetwork=1&gender=male&nicename=Sam&socialimageurl=https://graph.facebook.com/1008823838/picture }

响应: -     ****有时我会得到不好的错误或这个****

2014-02-06 13:37:01.426 Flokk[1561:a0b] Request Failed with Error: Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (JSON text did not start with array or object and option to allow fragments not set.) UserInfo=0xc953c20 {NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}, {
    NSDebugDescription = "JSON text did not start with array or object and option to allow fragments not set.";
}

0 个答案:

没有答案