How can I change in my WebView the default string of User-Agent?
@IBOutlet weak var myWbView: UIWebView!
let myURL = NSURL(string: "http://http://web-example")
let myURLRequest:NSURLRequest = NSURLRequest(URL: myURL!)
myWbView.loadRequest(myURLRequest)
Changing User-Agent allows you to mimic, spoof or fake other browsers, devices or search engine spiders. The extension does not render web pages in the same way as the selected one. User-Agent Switcher is primarily for developers who want to test how a page responds to different browsers.
Select the “Network“. Select the “Menu” icon located at the upper-right corner, then choose “More tools” > “Network conditions“. Uncheck the “Select automatically” check box, then choose the user agent you wish to use. in the drop-down menu.
It's not possible to change your user agent string on iPhone. The user agent string you provided is the standard string that an iPhone uses; nothing out of the ordinary there.
To open them, click the settings menu and select “F12 Developer Tools” or just press F12 on your keyboard. The developer tools will open in a separate pane at the bottom of the window. Click the “Emulation” tab and choose a user agent from the “User agent string” box.
If you want to set User-Agent HTTP header for your request that is going to be used for Web-view loading,
let userAgent = "Custom User Agent";
let myURL = NSURL(string: "http://http://web-example")
let myURLRequest:NSURLRequest = NSMutableURLRequest(URL: myURL!)
myWbView.loadRequest(myURLRequest)
myURLRequest.setValue(userAgent, forHTTPHeaderField: "User-Agent")
If you want to set User-Agent for all requests in your app, see this question How can I set the "User-Agent" header of a UIWebView in Swift
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With