0

我试图从 Xcode(使用 RestKit)发布到 WCF 服务。这是我的代码:

   NSDictionary *queryParams;
    queryParams = [NSDictionary dictionaryWithObjectsAndKeys:
                   @"1.0",@"oauth_version",
                   @"33333",@"oauth_nonce",
                   @"HMAC-SHA1",@"oauth_signature_method",
                   @"1323",@"oauth_timestamp",
                   @"rrr", @"oauth_consumer_key",
                   @"t672hpIerersdsfc", @"oauth_signature", nil];

    RKObjectManager *objectManager = [RKObjectManager sharedManager];

    RKURL *baseURL = [RKURL URLWithBaseURLString:@"http://myServer:80/appccservice.svc"];
    objectManager = [RKObjectManager objectManagerWithBaseURL:baseURL];


    objectManager.client.baseURL = baseURL;
    objectManager.client.authenticationType = RKRequestAuthenticationTypeOAuth1;
    objectManager.client.username = @"lsantos";
    objectManager.client.password = @"clave";

    NSString *resourcePath = [@"/json/post" stringByAppendingQueryParameters:queryParams];

    [RKObjectManager sharedManager].serializationMIMEType = RKMIMETypeJSON;
    RKObjectMapping *userSerialization = [RKObjectMapping mappingForClass:[NSMutableDictionary class]];

    [userSerialization mapKeyPath:@"name" toAttribute:@"nombreNovia"];
    [userSerialization mapKeyPath:@"tel" toAttribute:@"fecha"];


    RKObjectMapping *serialize = [userSerialization inverseMapping];


    [[RKObjectManager sharedManager].mappingProvider setSerializationMapping:serialize forClass:[User class]];

    [[RKObjectManager sharedManager].router routeClass:[User class] toResourcePath:resourcePath forMethod:RKRequestMethodPOST];

    User *data = [User new];
    data.nombreNovia = @"joaquin";
    data.fecha = @"4344";


    [[RKObjectManager sharedManager] postObject:data delegate:self];

我使用了 RKLogConfigureByName 并得到了这个:

要求:

URLRequest '<NSMutableURLRequest http://myServer:80/appccservice.svc/json/post?oauth_timestamp=32432304&oauth_nonce=123123&oauth_version=1.0&oauth_consumer_key=key&oauth_signature_method=HMAC-SHA1&oauth_signature=t672hasdfdsfsdsdceVBFqKc>'. HTTP Headers: {
    Accept = "application/json";
    "Accept-Encoding" = gzip;
    Authorization = "OAuth oauth_signature=\"bEmMvO3sdfsdfsdfcdc\"";
    "Content-Length" = 31;
    "Content-Type" = "application/json";
}. HTTP Body: {"tel":"4344","name":"joaquin"}.

我认为该请求一切正常,数据在 HTTP 正文中。

同时在回复中:

   Connection = "Keep-Alive";
    "Content-Length" = 7;
    "Content-Type" = "application/json; charset=utf-8";
    Date = "Thu, 27 Sep 2012 12:34:08 GMT";
    "Proxy-Connection" = "Keep-Alive";
    Server = "Microsoft-IIS/7.5";
    Via = "1.1 ISASERVERSM";
    "X-Powered-By" = "ASP.NET";
}

当对象为空时,我的方法返回空,因此 WCF 看不到数据。

2012-09-27 08:34:05.056 RESTPRUEBA2[6698:fb03] T restkit.network:RKResponse.m:231 Read response body: "empty"

我在 didFailLoadWithError 上遇到了这个错误

2012-09-27 09:11:25.500 RESTPRUEBA2[6698:fb03] error encontrado: Error Domain=JKErrorDomain Code=-1 "Expected either '[' or '{'." UserInfo=0x88d89c0 {JKAtIndexKey=7, JKLineNumberKey=1, NSLocalizedDescription=Expected either '[' or '{'.}

有趣的是,我在 Firefox 中使用带有相同 URL 和数据的 RestClient 插件证明了我的 WCF,并且一切正常。

4

1 回答 1

0

此问题表明您的远程系统返回的 JSON 解析不正确。来自JKErrorDomainJSONKit,正在使用的 JSON 解析器。获取您的响应正文并在http://jsonlint.com/上对其进行验证并修复解析错误。

于 2012-09-28T14:09:06.660 回答