Sometimes AdNetwork needs the same user agent in HTTP header during network requests. Is there any way to get the default browser’s user agent in Android? [import]uid: 214104 topic_id: 35517 reply_id: 335517[/import]
Hi,
The below code is the short explanation of what you ask. The setHeader is the important part of this. You can set your own user agent header then you can use the setHeader method.
private String url = “http://myfancyurl.com/”;
private String ua = “My Custom UA Header String”;
private HttpPost post = new HttpPost(url);
post.setHeader(“User-Agent”, ua);
For android development & iPhone app development needs please visit :
http://orange949.com/atlanta-application-development [import]uid: 220916 topic_id: 35517 reply_id: 141165[/import]
Thank you for your reply, Thomas.
But my problem is to get user agent, not set it.
To be more specific, I am trying to implement Smaato AdNetwork in Ad-Mediator-for-Corona (https://github.com/deniza/Ad-Mediator-for-Corona).
It needs two phases to complete the Smaato job. The first phase is to request banner, and the other phase is to use System.OpenUrl( ) when user clicks the banner. I complete the first phase with no problem (by using network.request with self-defined user agent). But when the user clicks the banner, OpenUrl( ) will lanunch browser to show the download page (but in this session, it uses browser’s user agent to access the server). Due to the inconsistency of user agent, the server redirects the link to a blank page (not download page).
Thus, I hope Corona could support such function to get the default user agent. Or, is there any method to get the default browser’s user agent? Thanks! [import]uid: 214104 topic_id: 35517 reply_id: 141515[/import]
Hi,
The below code is the short explanation of what you ask. The setHeader is the important part of this. You can set your own user agent header then you can use the setHeader method.
private String url = “http://myfancyurl.com/”;
private String ua = “My Custom UA Header String”;
private HttpPost post = new HttpPost(url);
post.setHeader(“User-Agent”, ua);
For android development & iPhone app development needs please visit :
http://orange949.com/atlanta-application-development [import]uid: 220916 topic_id: 35517 reply_id: 141165[/import]
Thank you for your reply, Thomas.
But my problem is to get user agent, not set it.
To be more specific, I am trying to implement Smaato AdNetwork in Ad-Mediator-for-Corona (https://github.com/deniza/Ad-Mediator-for-Corona).
It needs two phases to complete the Smaato job. The first phase is to request banner, and the other phase is to use System.OpenUrl( ) when user clicks the banner. I complete the first phase with no problem (by using network.request with self-defined user agent). But when the user clicks the banner, OpenUrl( ) will lanunch browser to show the download page (but in this session, it uses browser’s user agent to access the server). Due to the inconsistency of user agent, the server redirects the link to a blank page (not download page).
Thus, I hope Corona could support such function to get the default user agent. Or, is there any method to get the default browser’s user agent? Thanks! [import]uid: 214104 topic_id: 35517 reply_id: 141515[/import]