如何在UIWebView中处理代理设置? [英] How to deal with proxy setting in UIWebView?

查看:98
本文介绍了如何在UIWebView中处理代理设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习为iPhone创建自己的网络浏览器。我使用 UIWebView ,并使用这篇文章,我可以轻松创建它。

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

但问题出现时我必须在代理服务器后面这样做。我使用这篇文章在Mac OS X中设置Squid,并设置了Mac OS X网络首选项要使用这个新代理,我的应用程序将不再起作用。我在iPhone模拟器中尝试Safari,它将显示登录代理的用户名和密码。

But the problem arises when I had to do it behind a proxy 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.

我如何在自己的UIWebView中完成?
在第一项任务中,也许它足以硬编码。

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

非常感谢

推荐答案

嗯,这是我第一次回答了我自己的问题。
它很容易解决:使用这个库: ASIHTTPRequest 。所以我改变了我的代码:

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];

进入:

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.

谢谢

这篇关于如何在UIWebView中处理代理设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆