2017-02-03 44 views
0

在我的目標C代碼中,我嘗試訪問SOAP Web服務,但得到了錯誤:「線程1:EXC_BAD_ACCESS(代碼= EXC_I386_GPFLT) 「近以下行。在SOAP請求中線程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

在哪條線上你有這個錯誤? 「httpBodySoapMsg參數附近」根本不清楚 –

+0

@Anton Malmygin - 請檢查更新 – appleBoy21

+0

您是否嘗試在此行上設置斷點並檢查_encryptedUsername,_encryptedPassword,nonce,摘要的值? –

回答

2

聲明你的屬性爲strongassign

@property (strong, nonatomic) NSString *encryptedUsername; 
@property (strong, nonatomic) NSString *encryptedPassword; 
+0

是的,你是對的。解決了這個問題。謝謝。但我有一個問題。我們總是使用強大的UI組件。那麼爲什麼我們在NSString中使用Strong?分配有什麼問題?我可以使用保留嗎? – appleBoy21

+0

剛纔我用保留成功地執行了代碼。它也在工作。 – appleBoy21

+0

當您使用ARC時,'strong'(近似)像'保留'的別名。 –

相關問題