在我的目标C代码中,我正在尝试访问SOAP Web服务,但错误是错误:“线程1:EXC_BAD_ACCESS(代码= EXC_I386_GPFLT)”靠近以下行。
NSString *httpBodySoapMsg = [NSString stringWithFormat:
@"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"......
"</x:Envelope>\n", _encryptedUsername,_encryptedPassword, nonce, digest];
以下是我的完整代码。
#pragma mark - login request method
- (void)sendValidateEmailRequest {
NSString *nonce = [NSString stringWithFormat:@"%ld", (long)(NSTimeInterval)([[NSDate date] timeIntervalSince1970])];
NSString *digest = [Utils sha1:[NSString stringWithFormat:@"%@%@%@", _textUsername.text, nonce, _textPassword]]; // input is forsha
NSString *httpBodySoapMsg = [NSString stringWithFormat:
@"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
"<x:Envelope xmlns:x=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:mob=\"https://billing.eukhost.com/webservices/mobile_service_new?wsdl\">\n"
"<x:Header/>\n"
"<x:Body>\n"
"<mob:validate_email>\n"
"<mob:email>%@</mob:email>\n"
"<mob:password>%@</mob:password>\n"
"<mob:nonce>%@</mob:nonce>\n"
"<mob:digest>%@</mob:digest>\n"
"</mob:validate_email>\n"
"</x:Body>\n"
"</x:Envelope>\n", _encryptedUsername, _encryptedPassword, nonce, digest];
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:DEMO_URL]];
[urlRequest setValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[urlRequest setValue:[NSString stringWithFormat:@"%@%@", DEMO_URL, VALIDATE_EMAIL] forHTTPHeaderField:@"SOAPAction"];
[urlRequest setValue:@"Basic YjBlMDc2ZjAxZjFjZjAyODc6ODQ0NzI0ZGMyYjMwNWM4MzA=" forHTTPHeaderField:@"Authorization"];
[urlRequest setValue:_encryptedUsername forHTTPHeaderField:@"PHP_AUTH_USER"];
[urlRequest setValue:_encryptedPassword forHTTPHeaderField:@"PHP_AUTH_PW"];
NSString* deviceId = [[[UIDevice currentDevice] identifierForVendor] UUIDString]; // IOS 6+
[urlRequest setValue:deviceId forHTTPHeaderField:@"PHP_AUTH_DEVICE"];
// @"96c6754c9dc3b654517c5"
NSString *msgLength = [NSString stringWithFormat:@"%ld", (long)(httpBodySoapMsg.length)];
[urlRequest setValue:msgLength forHTTPHeaderField:@"Content-Length"];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setHTTPBody:[httpBodySoapMsg dataUsingEncoding:NSUTF8StringEncoding]];
RestApi *restApi = [RestApi sharedManager];
restApi.delegate = self;
[restApi httpRequest:urlRequest withResponseId:VALIDATE_EMAIL_ID];
}
答案 0 :(得分:4)
将您的属性声明为strong
而不是assign
@property (strong, nonatomic) NSString *encryptedUsername;
@property (strong, nonatomic) NSString *encryptedPassword;