MYSTERY ZILLION တွင် English သို့မဟုတ် Unicode ဖြင့်သာ အသုံးပြုခွင့်ရှိသည်။ ဇော်ဂျီ ၊ ဧရာ စသည်တို့ကို အသုံးပြုခွင့် မရှိ။ Unicode fonts များမှာ Mon3,Yunghkio, Myanamr3 စသည်များ အသုံးပြုနိုင်သည်။ Unicode Guide ကို ဒီမှာ Download ချပါ။ Zawgyi to Unicode Converter
Don't share ebook or software if nobody request. You can find free book websites on here. We are welcome for discussion or asking question instead.

Authentication challenge

edited January 2013 in iOS Devlopment
Hello everyone,
When I open some website, I see this. <br>
<a href="http://tinypic.com?ref=2f08uip"; target="_blank"><img src="http://i45.tinypic.com/2f08uip.png"; border="0" alt="Image and video hosting by TinyPic"></a>
<br>

I need to auto-sign in that one so that pop-up will not appear on ipad App. <br>
I have read through this but I don't know how to do. <br>
http://developer.apple.com/library/mac/#documentation/cocoa/conceptual/urlloadingsystem/Articles/AuthenticationChallenges.html
<br>
http://blog.mugunthkumar.com/articles/iphone-tutorial-authenticating-with-a-restful-service-using-nsurlcredential/
<br>
I have used uiwebview also and part of the code is shown below.

<pre lang="oc">
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{

//look at the request ..whether the address has same IP/host name
// request.URL.host
//key in b4 hand username/password/ hostname
//do the handshake
//return NO
//TODO: add rejection or special handling of specific types of web requests here
//if(activeWebView == webView) self.txt_url.text = [webView.request.URL absoluteString];


NSLog([NSString stringWithFormat:@%@",request]);
self.lbl_error.hidden = YES; //hide error message label
return YES;
}
</pre>

I would like to know where I can start and write the code. The main file is uploaded below.
http://www.mediafire.com/?h9mxayf86k7jhi6

With Regards,


မှတ်ချက်များ

  • edited January 2013 Administrators
    <pre lang="oc">
    -(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
    </pre>

    is a UIWebView Delegate.

    Do you want to show Auth Screen or do you want to skip ?

    If you want to skip , you need to add Basic Authorization Header in UIWebView Request.

    The easiest way is using https://github.com/oscardelben/UIWebViewBasicAuth
  • edited January 2013 Registered Users
    Thanks bro. I want to skip. It is working. But now I need to do that with NTLM credentials. How can I do ?<br>

    <pre lang="oc">
    NSURLProtectionSpace *protectionSpace = [[NSURLProtectionSpace alloc]
    initWithHost: hostname
    port: 80
    protocol: @http
    realm: hostname
    authenticationMethod:NSURLAuthenticationMethodNTLM];

    [[NSURLCredentialStorage sharedCredentialStorage] setDefaultCredential:[NSURLCredential credentialWithUser:_username password:_password persistence:NSURLCredentialPersistenceForSession] forProtectionSpace:protectionSpace];
    </pre>
    <br>
  • edited January 2013 Registered Users
    Thanks bro. Sorry to bother you again. I still cannot connect. I write like this. I also don't know what to set "realm". <br>
    When I run, I see NSLog(@got auth challange); but not see NSLog(@received response via nsurlconnection);.<br>
    But, the page doesn't load and I don't know whether it is already sign-in or not. It should be start page. How should I do bro?

    <pre lang="oc">
    -(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{

    NSLog(@Did start loading: %@ auth:%d", [[request URL] absoluteString], _authed);

    if([request.URL.host isEqualToString:@42.61.46.2])
    {
    NSURLConnection* connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
    [connection start];

    NSLog(@%@",request);
    return NO;
    }


    self.lbl_error.hidden = YES; //hide error message label
    return YES;
    }


    - (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
    {
    NSLog(@got auth challange);

    if ([challenge previousFailureCount] == 0)
    {
    NSURLProtectionSpace *protectionSpace = [[NSURLProtectionSpace alloc]
    initWithHost: @42.61.46.2
    port: 80
    protocol: @http
    realm: nil
    authenticationMethod:NSURLAuthenticationMethodNTLM];

    [[NSURLCredentialStorage sharedCredentialStorage] setDefaultCredential:[NSURLCredential credentialWithUser:@example password:@example persistence:NSURLCredentialPersistenceForSession] forProtectionSpace:protectionSpace];



    }
    else
    {
    [[challenge sender] cancelAuthenticationChallenge:challenge];
    }

    }


    - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
    {
    NSLog(@received response via nsurlconnection);

    NSString *url = @"http://42.61.46.2";
    NSURLRequest *urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];

    [activeWebView loadRequest:urlRequest];
    }


    - (BOOL)connectionShouldUseCredentialStorage:(NSURLConnection *)connection
    {
    return NO;
    }

    </pre>
  • edited January 2013 Registered Users
    But when I write like this, I can access. But, I have to use the first one. I would like to know how I should do. <br>
    <pre lang="oc">
    -(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
    if ([request.URL.host isEqualToString:@"http://42.61.46.2/"]) {
    [[NSURLConnection alloc] initWithRequest:request delegate:self];
    return NO;
    }

    NSLog([NSString stringWithFormat:@%@",request]);
    self.lbl_error.hidden = YES; //hide error message label
    return YES;
    }
    </pre>
  • edited January 2013 Registered Users
    I see the error.
    I should write like this. Thanks bro. Now it can connect already.
    if ([request.URL.host isEqualToString:@"http://42.61.46.2/"])
  • Administrators
    @KhatThu , glad to hear about that. Sorry for reply late. I don't know NTLM and need to research. I couldn't research at office hour.
  • Registered Users
    It's okay bro. You helped me every time when I face difficulties. :)
Sign In or Register to comment.