在我的应用程序中,我使用签署文档的web服务。我必须在SOAP调用中以base64格式发送documento。问题是,当我尝试发送像11mb一样的大文档时,base64(存储在NSString中)很大,SOAP消息被截断。NSString被截断
因此,我可以发送SOAP调用,并收回服务器错误。
是否有任何类可以存储大(非常大)的字符串?
编辑:这是我使用的代码:
为了将文档转换为Base64:
NSData *signData = [[NSFileManager defaultManager] contentsAtPath:self.pathDocument];
NSString *base64file = [signData base64EncodedString];
要执行的呼叫:
NSString *soapMsg = [NSString stringWithFormat:@"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:tem=\"http://tempuri.org/\" xmlns:seal=\"http://schemas.datacontract.org/2004/07\">"
"<soapenv:Header/>"
"<soapenv:Body>"
"<tem:Sign>"
"<tem:type>Signature</tem:type>"
"<tem:biometricState>%@</tem:biometricState>"
"<tem:idCertificate>%d</tem:idCertificate>"
"<tem:signatureProfile>%@</tem:signatureProfile>"
"<tem:signatureType>Default</tem:signatureType>"
"<tem:hashAlgorithm>Default</tem:hashAlgorithm>"
"<tem:options>%@</tem:options>"
"<tem:signingDocument>%@</tem:signingDocument>"
"</tem:Sign>"
"</soapenv:Body>"
"</soapenv:Envelope>",
aSign,
[aCertificado idCert],
tipoFirma,
flagFirma,
aDocument
];
NSString *stringURL = [NSString stringWithFormat:@"http://%@//Service/SignatureServiceBasic.svc", [settings servidor]];
NSURL *sRequestURL = [NSURL URLWithString:stringURL];
NSMutableURLRequest *myRequest = [NSMutableURLRequest requestWithURL:sRequestURL];
NSString *sMessageLength = [NSString stringWithFormat:@"%d", [soapMsg length]];
[myRequest addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[myRequest addValue:@"http://tempuri.org/ISignatureServiceBasic/Sign" forHTTPHeaderField:@"SOAPAction"];
[myRequest addValue: sMessageLength forHTTPHeaderField:@"Content-Length"];
[myRequest setHTTPMethod:@"POST"];
[myRequest addValue:@"Jakarta Commons-HttpClient/3.1" forHTTPHeaderField:@"User-Agent"];
[myRequest setHTTPBody: [soapMsg dataUsingEncoding:NSUTF8StringEncoding]];
NSString* username = [settings usuario];
NSString* password = [settings pass];
NSString *authStr = [NSString stringWithFormat:@"%@:%@", username, password];
NSData *authData = [authStr dataUsingEncoding:NSASCIIStringEncoding];
NSString *authValue = [NSString stringWithFormat:@"Basic %@", [authData base64EncodingWithLineLength:80]];
[myRequest setValue:authValue forHTTPHeaderField:@"Authorization"];
signConnection = [[NSURLConnection alloc] initWithRequest:myRequest delegate:self];
if(signConnection) {
webResponseData = [NSMutableData data];
}else {
NSLog(@"Some error occurred in Connection");
}
aDocument
是文档在base64中。
在此先感谢!
NSString可以存储任何大小,只要它适合内存。你可能会在别处找到你的问题。你应该显示你的代码。 – CouchDeveloper