在我的应用中,我正在使用对文档进行签名的Web服务。我必须在SOAP调用中以base64format发送文档。问题是,当我尝试发送一个11mb的大文件时,base64(存储在NSString中)很大,并且SOAP消息被截断了。
因此,我可以适当地发送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中的文档。提前致谢!
最佳答案
不,没有这样的课程..但是你可以尝试一件事
尝试以块而不是大文件的形式创建数据,然后使用流将该数据发送到服务器。
关于ios - NSString被截断,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20472107/