AFNetworking 如何处理 _NSInlineData?

AFNetworking what to do with _NSInlineData?

我正在尝试使用 soap 请求连接到服务器以获取一些数据。我设置了以下内容:

NSString *soapmsg = [NSString stringWithFormat:
                     @"<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:ns=\"http://www.schneider-electric.com/common/dataexchange/2011/05\">"
                        @"<soap:Header/>"
                        @"<soap:Body>"
                            @"<ns:GetValuesRequest>"
                                @"<ns:GetValuesIds>"
                                    @"<ns:Id>%@</ns:Id>"
                                @"</ns:GetValuesIds>"
                            @"</ns:GetValuesRequest>"
                        @"</soap:Body>"
                     @"</soap:Envelope>",
                     KTempId];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:KUrl]];
[request addValue: @"application/soap+xml; charset=utf8"  forHTTPHeaderField:@"Content-Type"];
[request addValue:[NSString stringWithFormat:@"%@", KUrl] forHTTPHeaderField:@"SOAPAction"];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:[soapmsg dataUsingEncoding:NSUTF8StringEncoding]];

NSURLCredential *credential = [NSURLCredential credentialWithUser:kWebPassword password:kWebPassword persistence:NSURLCredentialPersistenceForSession];

AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation.securityPolicy setAllowInvalidCertificates:YES];
[operation.securityPolicy setValidatesDomainName:NO];
[operation setCredential:credential];

[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation * _Nonnull operation, id  _Nonnull responseObject)
{
    NSLog(@"type: %@", [responseObject class]);
    NSDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil];
    NSString *tmpString = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
    NSLog(@"dict count: %lu\n And string: %@", (unsigned long)[responseDictionary count], tmpString);
}
failure:^(AFHTTPRequestOperation * _Nonnull operation, NSError * _Nonnull error)
{
    NSLog(@"Failure \n%@", [error localizedDescription]);
}];

[[NSOperationQueue mainQueue] addOperation:operation];

这有效并且 returns 以下 NSLogs:

type: _NSInlineData dict count: 0

 "And string: <?xml version="1.0" encoding="UTF-8"?>"
"<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:EWSv122="http://www.schneider-electric.com/common/dataexchange/2011/05/DataExchangeInterface/Fault" xmlns:EWSv121="http://www.schneider-electric.com/common/dataexchange/2011/05">"
"<SOAP-ENV:Header></SOAP-ENV:Header>"
    "<SOAP-ENV:Body>"
        "<EWSv121:GetValuesResponse>"
            "<EWSv121:GetValuesItems>"
                "<EWSv121:ValueItem>
                "<EWSv121:Id>01/HC RT/Verdieping1/Noord/201/T</EWSv121:Id>"
                    "<EWSv121:State>0</EWSv121:State>"
                    "<EWSv121:Value>20.769998550415</EWSv121:Value>"
                "</EWSv121:ValueItem>"
            "</EWSv121:GetValuesItems>"
        "<EWSv121:GetValuesErrorResults>"
        "</EWSv121:GetValuesErrorResults>"
        "</EWSv121:GetValuesResponse>"
    "</SOAP-ENV:Body>"
"</SOAP-ENV:Envelope>"

所以连接正常。但是我只得到一个 NSString 并且似乎无法将它解析为 NSDictionary 或其他任何东西。

我试过设置:

operation.responseSerializer = [AFJSONResponseSerializer serializer];

但随后我收到一条错误消息:

失败 请求失败:不可接受的内容类型:application/soap+xml

那么我应该如何处理 responseObject?

编辑: 我向 NSJsonSerializer 添加了一个 NSError,这是它记录的内容:

解析错误:无法读取数据,因为它的格式不正确。

愚蠢的我,我确实期待 XML (SOAP) 数据。我很久以前就解决了这个问题,但忘了回答我自己的问题,所以这个问题可以关闭了。