httptoolkit / httptoolkit-android

Automatic Android interception & debugging with HTTP Toolkit, for Android
https://httptoolkit.com
GNU Affero General Public License v3.0
476 stars 72 forks source link

Oh no! We couldn't connect to HTTP Toolkit. Is it running, and connected to the same network as this device? #11

Closed thorbn closed 1 year ago

thorbn commented 1 year ago

Hello. Whenever I launch the Android app and try connecting it to my Windows machine (which is on the same network) I get the error stated in the title. I haven't found myself having any issues with other apps. I have a Xiaomi Note 11 running Android version 11 RKQ1.200826.002 and MIUI-Version MIUI Global 12.5.7 Stable 12.5.7.0(RKFEUXM). My phone isn't rooted. If you guys need any more info from me I would be happy to provide it.

pimterry commented 1 year ago

Thanks @thorbn. When this happens, does anything appear on the 'View' page on your computer? If the phone can connect to your computer, there should be at least one http://android.httptoolkit.tech/config request there that's sent during setup.

thorbn commented 1 year ago

Hello. There is nothing appearing in the "View" tab on my computer. I don't get anything on my computer, just the error message on my phone.

pimterry commented 1 year ago

Ok, it's almost certain that there's some kind of connectivity issue in that case. At this stage the app is sending an HTTP request to your computer on your proxy port (8000, by default) testing each of your computer's IP addresses to see how to connect, and it's not arriving on any of them.

There's lots of things that can cause this unfortunately. Some networks don't allow connectivity between local devices, which would do this, as would a firewall on your computer that blocks all connections to that port.

You can test connectivity by trying to open http://<your computer's IP>:8000/ in a browser on your device. If you can connect, you should see a request appear on the View page, and see a response appear in the browser on your phone (typically a message like 'Passthrough loop detected' unless you've added a custom rule, because you're not really supposed to make direct requests to the proxy). In this case though, you'll probably see an error that may tell you more about the connectivity issues.

If none of that comes up with any clues, you can also try looking at the raw logs from the device. Those are available via ADB with adb logcat -T1, and you'll see messages in there like:

tech.httptoolkit.android.MainActivity: Connecting to VPN from URL: https://android.httptoolkit.tech/connect/?data=...
tech.httptoolkit.android.ProxySetup: URL data is {"addresses":["$IP", "$ANOTHER_IP"],"port":8000,"localTunnelPort":8000,"certFingerprint":"QWEASDQWEASDqweasdqweasd="}
tech.httptoolkit.android (kotlinx.coroutines.SupervisorCoroutine): Validating proxy info ProxyInfo(addresses=[$IP, $ANOTHER_IP], port=8000, localTunnelPort=8000, certFingerprint=QWEASDQWEASDqweasdqweasd=)
tech.httptoolkit.android (kotlinx.coroutines.SupervisorCoroutine): Proxy tests started
tech.httptoolkit.android (kotlinx.coroutines.UndispatchedCoroutine): Testing proxy $IP:8000
tech.httptoolkit.android (kotlinx.coroutines.UndispatchedCoroutine): Testing proxy $ANOTHER_IP:8000
tech.httptoolkit.android (kotlinx.coroutines.UndispatchedCoroutine): Error testing proxy address $IP: java.net.ConnectException: Failed to connect to $IP
tech.httptoolkit.android (kotlinx.coroutines.UndispatchedCoroutine): Error testing proxy address $ANOTHERIP: java.net.SocketTimeoutException: connect timed out

That will at least tell you exactly what IPs were used, and what the connection errors are. It's also technically possible something else could be failing here and causing this behaviour, and that will be listed in here if so, but I've never seen anything but connectivity problems cause cases like this so I'd be pretty surprised.

thorbn commented 1 year ago

Thanks for your help. I deactivated all firewalls that could be causing this and now it's working!

pimterry commented 1 year ago

Excellent! I'll close this now, glad that sorted it for you :+1: