简体   繁体   中英

Run a UIWebView through an external server (Different IP Address and Port)

I'm trying to make an iOS application which is essentially acting like a proxy server. It has a UIWebview which displays content just like Safari would. However, what I want to do is have all data traffic coming from an external IP address and port such as those suggested here: http://hidemyass.com/proxy-list/

My current code is just the simple code of:

NSString *fullURL = @"http://www.google.com";
NSURL *url = [NSURL URLWithString:fullURL];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[self.webView loadRequest: request];

Say I had the IP Address: 177.101.8.13 and the port: 8080 - How could I implement that into my code above so the request comes from that server, as opposed to the server/network I am currently on? I had a look at ASIHTTPRequest but couldn't see how I could implement that in this situation...

Thanks!

*(Sorry about my terminology regarding this)

If you setup a proxy server in the device's settings, NSURLConnection automatically uses the proxy server. Otherwise, you have to rewrite the request.

All requests over proxy servers use HTTP 1.1. You use the IP address of the proxy server in the request, but in the Host header, you send the actual host that you are attempting to reach. Include the port in the Host header if it's other than 80.

Use NSMutableURLRequests 's setValue:forHTTPHeaderField: method to set specific headers.

Where request is the NSMutableURLRequest:

[request setValue:@"google.com" forHTTPHeaderField:@"Host"];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM