How can I redirect HTTP requests made from an iPad

2019-01-20 22:01发布

Since on an iPad we cannot edit the hosts file (without jailbreaking), how can we arbitrarily redirect web traffic to another url?

This would be important for something such as developing a website that uses a Virtual Host configuration where you want to redirect to a development machine.

(This is related to this question: Can I edit an iPad's host file?)

16条回答
我只想做你的唯一
2楼-- · 2019-01-20 22:29

Setup the hosts file on a computer running a proxy server such as Fiddler or Charles, and configure the iPad to use that computer as an HTTP proxy.

Here are instructions for how to do this with Fiddler: http://conceptdev.blogspot.com/2009/01/monitoring-iphone-web-traffic-with.html

And this is for Charles: http://www.ravelrumba.com/blog/ipad-http-debugging/

查看更多
时光不老,我们不散
3楼-- · 2019-01-20 22:35

The way to get around this limitation of the iPad is to use a HTTP proxy server, such as Squid running on another machine where you can edit the hosts file.

On the iPad Under Settings -> Network -> Wi-Fi -> (Your network) There is a HTTP Proxy setting which can be set to manual. Enter you proxy information here.

Once this is set up you would be able to manipulate the iPad as if you were changing the hosts file.

查看更多
成全新的幸福
4楼-- · 2019-01-20 22:35

Internal DNS Server is one of the option but that was too cumbersome to implement. We tried installing squid as proxy server but that also didnt work because it was redirecting the URL to new server and this redirection was seen on browser URL too.

Thing which finally worked for us was to install Fiddler on one of the server and use this server as the proxy server on ipad. Fiddler also has a feature to map sub-domains to IP address i.e. something similar to /etc/hosts.

查看更多
Ridiculous、
5楼-- · 2019-01-20 22:35

Nice tutorial to do so: http://egalo.com/2012/05/29/testing-mac-web-site-using-local-hostname-on-mobile-device/

An other way is to connect the IPad via Local Hotspot with my MAC OS X and establish an port-forwarding to the development VM. To achieve this I'v done the following Steps:

  • on MAC OS X create a WLAN-Hotspot Link how to do this
  • connect the iPAD with the Hotspot-WLAN (on iPAD >> Settings >> WLAN)
  • Add the ServerAlias to the local development-VM (details below)
  • establish ssh-portforwarding
    ssh -NL <IP-of-hotspot-host>:<source-port>:<url-to-local-vm>:80 <user-to-vm>
  • int the iPADs Browser open the page with the IP
    <IP-of-hotspot-host>:<source-port>

Where to get 'IP-of-hotspot-host':

After created hotspot there is a WLAN-Point in
MAC OS X system settings >> Network >> WLAN

Adding the ServerAlias:

At my development-VM (Apache2) in /etc/apache2/sites-available/dkr.dev.local I had to add the following:

<VirtualHost *:80>  
    ...  
    ServerAlias <IP-of-hotspot-host>  
    ...  
</VirtualHost>
查看更多
Bombasti
6楼-- · 2019-01-20 22:36

I would try Relay Server (part of Afaria) which can re-direct mobile traffic based on profiles.

Update: tremoloqui's answer seems less trouble and far cheaper.

查看更多
The star\"
7楼-- · 2019-01-20 22:44

It's also possible to use Weblock - AdBlock for iOS app (available for $1.99 here: https://itunes.apple.com/us/app/weblock/id558818638?mt=8) to create web traffic redirects.

This allows you to redirect any traffic matching certain rule to specified IP address. This will emulate adding an entry to /etc/hosts on your iOS device. If the hostname set in requests is handled by the IP you direct your traffic to, you can use this to test private API or even sniff traffic sent from other apps or websites. This unfortunately works only for http/https connections.

All this can be done only while on Wi-Fi (one of Weblock's limitations). There main advantage is that you can easily configure everything from your iOS device and there is no need to mess with DNS/proxy server configuration.

Here's an example:

  1. I've configured Weblock like this: http://i.stack.imgur.com/c5SUh.png
  2. Opened Safari and typed in www.google.com as URL
  3. This is the output in terminal on my Mac listening for connection on port 1234:

    macbook-pro-tk:~ kpr$ nc -l -v -v 1234
    GET http://www.google.com/ HTTP/1.1
    Host: www.google.com
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    Proxy-Connection: keep-alive
    PREF=ID=7722bc3c844a7c26:TM=1402073839:LM=1402073839:S=5bSJJsM2p0HgUP7L
    User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 7_1_1 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Version/7.0 Mobile/11D201 Safari/9537.53
    Accept-Language: en-us
    Accept-Encoding: gzip, deflate
    Connection: keep-alive

Weblock is also good to selectively redirect some URL's with regular expressions. You could redirect queries to certain endpoint only, while all other queries go to the IP returned from the DNS. This actually allows for even more fitting configuration that /etc/hosts does.

Example: If I create a URL redirect rule for htt*://somedomain.com/api/login* and some IP and port, I will see only traffic from this URL at this IP and port, while all other traffic to somedomain.com will go directly to the IP returned by the DNS. Notice it will work for both /api/login and /api/login?someparam=somevalue thanks to the wildcard * sign at the end of the rule.

查看更多
登录 后发表回答