2017-12-13 2 views
0

나는 그것에 대해 알 수있는 모든 블로그를 시도했다. 그러나 NTLM 챌린지로 상태 401을 해결할 수는 없습니다.Xamarin.iOS에서 NTLM 인증으로 401을 얻는 방법

그래서 기본적으로 회사 서버에서 호스팅되는 사용자의 프로필 사진을 가져와야합니다.

브라우저에서 URL을 누를 때 사용자 이름과 암호를 묻는 메시지가 나타나면 이미지를 제공합니다.

하지만 같은 내가

Xamarin.iOS

달성 할 수없는 나는 다음은 내가 함께 노력하고 코드 조각입니다. 내가 얻고

  var credentials = new NetworkCredential("myUserName", "Password", "domain"); 

     var handler = new HttpClientHandler { Credentials = credentials, UseDefaultCredentials = false }; 
     handler.AllowAutoRedirect = false; 
     var client = new HttpClient(handler); 
     try 
     { 
      var response = await client.GetAsync("https://mycustomUrl.net/User%20Photos/Profile%20Pictures/eurn_martin_kremmer_MThumb.jpg"); 
      Console.WriteLine(response); 
     } 
     catch (Exception ex) 
     { 
      Console.WriteLine(ex); 
     } 

응답이있는 NSURLConnection과 같은 요청을 던질 때 와우,이 솔루션은 파이로 쉽게 몰랐

StatusCode: 401, ReasonPhrase: 'Unauthorized', Version: 1.1, Content: System.Net.Http.StreamContent, Headers: 
{ 
Server: Microsoft-IIS/8.0 
SPRequestGuid: 5725369e-b047-40c5-d468-0417992ffab3 
request-id: 5725369e-b047-40c5-d468-0417992ffab3 
X-FRAME-OPTIONS: SAMEORIGIN 
SPRequestDuration: 2 
SPIisLatency: 0 
WWW-Authenticate: NTLM 
X-Powered-By: ASP.NET 
MicrosoftSharePointTeamServices: 15.0.0.4779 
X-Content-Type-Options: nosniff 
X-MS-InvokeApp: 1; RequireReadOnly 
Date: Wed, 13 Dec 2017 13:55:26 GMT 
Content-Length: 0 
} 
+0

http 호출에는 예외가 있으며 https에도 예외가 필요합니까? –

+0

o 예, 내 잘못입니다. –

답변

0

입니다. 여기

,

responseData = new NSMutableData(); 
request = new NSMutableUrlRequest(uri,NSUrlRequestCachePolicy.UseProtocolCachePolicy, 6000); 
request.HttpMethod = "GET"; 
connection = new NSUrlConnection(request, this); 

이 시트릭스 MAM 환경에서 번거 로움없이 작동합니다.

하지만 시뮬레이터에서 테스트하려면 아래와 같이 처리해야합니다.

 public override void WillSendRequestForAuthenticationChallenge(NSUrlConnection connection, NSUrlAuthenticationChallenge challenge) 
    { 
     Console.WriteLine(challenge.ProtectionSpace); 

     if (challenge.PreviousFailureCount == 0) 
     { 

      NSUrlCredential cred = new NSUrlCredential(this.myUserName, this.myPass, NSUrlCredentialPersistence.None); 
      challenge.Sender.UseCredential(cred, challenge); 
     } 

    } 
관련 문제