2011-10-06 5 views
1

ios에서 보안 URL에 액세스하려고합니다. 기본적으로 url은 사용자에게 Username과 Password를 요구합니다. ios에서 사용자 이름과 비밀번호를 보내려면 어떻게해야합니까?ios에서 보안 URL에 액세스하는 방법

내 코드 여기 내가 JSON 파서 여기에

- (NSString *)stringWithUrl:(NSURL *)url{ 
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url 
              cachePolicy:NSURLRequestReturnCacheDataElseLoad 
             timeoutInterval:30]; 
// Fetch the JSON response 
NSData *urlData; 
NSURLResponse *response; 
NSError *error; 

// Make synchronous request 
urlData = [NSURLConnection sendSynchronousRequest:urlRequest 
           returningResponse:&response 
              error:&error]; 

// Construct a String around the Data from the response 
return [[[NSString alloc] initWithData:urlData encoding:NSUTF8StringEncoding] autorelease];} 


- (id) objectWithUrl:(NSURL *)url{ 
SBJsonParser *jsonParser = [[[SBJsonParser alloc]init] autorelease]; 
NSString *jsonString = [self stringWithUrl:url]; 

// Parse the JSON into an Object 
return [jsonParser objectWithString:jsonString error:nil]; } 

를 액세스하는 데 사용하고 방법은 내 사전에 JSON 키를 검색하고있어 코드의 조각입니다.

- (NSDictionary *) downloadFeed { 
id response = [self objectWithUrl:[NSURL URLWithString:@"http://mysite.com/Services/Secure.svc/GetList?id=2127"]]; 

NSDictionary *feed = (NSDictionary *)response; 
return feed; } 

누군가가 내가이 URL에 사용자 이름과 암호를 전달할 수있는 곳 알려주세요 수 있습니까?

+0

어떤 의미로 프롬프트가 표시됩니까? 웹 사이트의 로그인 양식 또는 [기본 HTTP 인증] (http://en.wikipedia.org/wiki/Basic_access_authentication)? – Alex

+0

기본 HTTP 인증, 더 명확한 그림을 얻기 위해 코드를 업데이트했습니다! – HardCode

+0

'http : // user : [email protected]/...' –

답변

3

단순히 기본 인증을 처리하는 ASIHTTPRequest으로 전환하거나 NSMutableRequest을 사용하고 base64로 인코딩 된 사용자 : 암호 쌍을 사용하여 Authorization 헤더를 올바르게 설정하십시오.

+0

+1, ASIHTTPRequest, 매우 편리하고 BSD 스타일의 라이센스. – jbat100

+0

로그인 컨트롤러에 ASIHTTPRequest를 사용하고 있습니다. 하지만 로그인 후 JSON Parser를 사용하고 있습니다. URL에 대한 자격 증명을 사용하는 것이 안전하지 않다고 생각하십니까? 그럼 배포판에서 HTTPS를 사용할 것입니다! – HardCode

+0

여기에 사용자 이름과 암호를 어디에 할당합니까? NSURL * url = [NSURL URLWithString : @ "http : // @ http : //mysite.com/Services/Secure.svc/GetList? id = 2127"]; ASIFormDataRequest * request = [ASIFormDataRequest requestWithURL : url]; [요청 setRequestMethod : @ "얻으십시오"]; – HardCode

관련 문제