问题
I'm making an app, it just loads a website. I need to modify the user agent of the http reqeust. I also need to cancel requests made by the site if URI matches a pattern (i.e. "ads").
How can I listen/control all HTTP requests made in my app is there an API for this?
回答1:
If it's just for you you can change the user agent on the phone in the user prefs (user.js file on your phone that you can access through adb shell
).
Otherwise your best option is to use a reverse proxy.
APP -> Reverse proxy -> Real website
The reverse proxy is a server application that has full control over the HTTP request and can strip off UA header or replace it with new ones etc.
Third one: Use the mozTCPSocket API to create HTTP requests to the server. If you only do GET it should not be that hard and you have full control over the request. If you only ever talk to one server it could be OK, but it'll be more work.
来源:https://stackoverflow.com/questions/25153906/http-request-modification-in-firefox-os