How to open url need username and password with uiwebview?

I want to open a URL that requires a password and username in UIWebview. For example, open my local Wi-Fi router (192.168.1.1). But when I try to execute the code, a popup like Safari does not require a password and username.

NSURL *url = [NSURL URLWithString:@"http://192.168.1.1"]; NSURLRequest *httpReq = [NSURLRequest requestWithURL:url]; [self._webView loadRequest:httpReq]; 

Since someone told me to use NSURLConnectionDelegate, I know this, but I don’t know how to show the authorized page in UIWebView.

+6
source share
3 answers

This will help

NSURL *url = [NSURL URLWithString:@"http://username: password@192.168.1.1 "]; NSURLRequest *httpReq = [NSURLRequest requestWithURL:url]; [self._webView loadRequest:httpReq];

+7
source

You need to implement the connection: didReceiveAuthenticationChallenge: in NSURLConnectionDelegate. For more information, see the Apple Authentication Issues URL Programming Guide.

+3
source

UIWebView does not provide any mechanism for identifying a response. So one solution is explained in the github UIWebViewHttpStatusCodeHandling project, which identifies the response status code (should be 404 in your case).

However, the main drawback is that for each request you need to use NSURLConnection and load the request again. But in this case, you can also cancel the NSURLConnection.

Another solution should be (possibly) using Java-Script. Find the Java script that provides the response status code.

+1
source

Source: https://habr.com/ru/post/895107/


All Articles