开发者

How to deal with proxy setting in UIWebView?

开发者 https://www.devze.com 2023-03-02 15:21 出处:网络
I am learning to create my own web browser for iPhone. I use UIWebView, and using this article, I can create it easily.

I am learning to create my own web browser for iPhone. I use UIWebView, and using this article, I can create it easily.

But the problem arises when I had to do it behind a prox开发者_运维问答y server. I set up Squid in Mac OS X using this article, and having set Mac OS X network preferences to use this new proxy, my application won't work anymore. I try the Safari inside iPhone Simulator, and it will display login for the username and password of the proxy.

How can I do it inside my own UIWebView? At first task, maybe it's adequate to hardcode it.

Many thanks


Well, this is the first time I answered my own question. It solved rather easily : use this library : ASIHTTPRequest. So I change my code from this :

NSURL *url = [NSURL URLWithString:[addressBar text]];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
[webView loadRequest:urlRequest];
[addressBar resignFirstResponder];

Into this :

NSString *urlAddress = @"http://www.google.com";
NSURL *url = [[NSURL URLWithString: [urlAddress stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] retain];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];

[request setUsername:@""];
[request setPassword:@""];

[request startSynchronous];

It will prompt for username & password if needed.

Thanks

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号