2011-02-07 4 views
0

+ 문자가있는 전화 번호를 포함하여 세부 정보를 서버에 요청하여 문제가 발생했습니다. 서버 쪽 끝에 + 문자가 표시되지 않습니다. 웹 서버에 URL 요청을 보내는 동안 + 문자를 처리하는 방법

curl = [curl stringByAppendingString:@"name="]; 
    curl = [curl stringByAppendingString:profileObj.name]; 
    curl = [curl stringByAppendingString:@"&email="]; 
    curl = [curl stringByAppendingString:profileObj.email]; 
    curl = [curl stringByAppendingString:@"&password="]; 
    curl = [curl stringByAppendingString:profileObj.password]; 
    curl = [curl stringByAppendingString:@"&phoneno="]; 
    curl = [curl stringByAppendingString:profileObj.phoneno]; // here my data is +919999999999 
    curl = [curl stringByAppendingString:@"&address="]; 
    curl = [curl stringByAppendingString:profileObj.address]; 
    curl = [curl stringByReplacingOccurrencesOfString:@"\n" withString:@""]; 

    NSString *escapedUrlString = [curl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 

    NSURL *finalURL = [NSURL URLWithString:escapedUrlString]; 

    [self updateStatus]; 
    if (internetConnectionStatus == NotReachable) 
    { 
     UIAlertView *reachbleAlert = [[UIAlertView alloc] initWithTitle:@"Network Error" 
                message:@"No Network Available. \n This Application requires network connectivity. " 
                delegate:self 
             cancelButtonTitle:@"Ok" 
             otherButtonTitles: nil]; 
     [reachbleAlert show]; 
     [reachbleAlert release]; 
     return; 
    } 
    else 
    { 

     NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; 
     NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:finalURL 
                    cachePolicy:NSURLRequestReloadIgnoringCacheData 
                   timeoutInterval:10]; 
     [theRequest setHTTPMethod:@"POST"]; 

     [[[NSURLConnection alloc] initWithRequest:theRequest delegate:self] autorelease]; 

     [pool release]; 

    } 

나는 선 아래 사용 :

NSString *escapedUrlString = [curl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 

서버에 요청하기 전에. 그래서 제발 + 문자를 처리하는 솔루션을 도와주세요.

답변

0

글쎄 +은 URL의 유효한 문자이므로 stringByAddingPercentEscapesUsingEncoding:에 의해 무시됩니다. + 표지판을 URL에 넣기 전에 수동으로 이스케이프해야합니다. 예 :

... 
curl = [curl stringByAppendingString:@"&phoneno="]; 
curl = [curl stringByAppendingString: [profileObj.phoneno stringByReplacingOccurencesOfString: @"+" with: @"%2B"]]; // here my data is +919999999999 
... 

NB %2B에 대해 확실하지 않습니다. 2B 또는 2B가 아니라, 그 질문입니다.

관련 문제