Simple User-Agent question

Hi,
I'm using the java.net.URL class to get an XML document.
However, the stupid server I'm requesting from automattically gives a 403 error if the User-Agent field of the request starts with "Java".
How can I change the User-Agent field of any URL or URLConnection request in one shot? I don't want to use URLConnection's setDefaultRequestProperty in every instance a request is made (the static class method is depracted) because I want to keep my code short.
I just want to do
URL url = new URL( "http://www.sdkjf.com/xml?blah=3" );
in = url.openStream( );
and then read in using my parser. I have not found in the API a method for setting the User-Agent once in an application. How do you do it?
thanks

The main issue was that there is there are already alot of XML requests made by just using a URL class and calling url.openStream() all over the application (1000s of classes)
so I was wondering if there was a method that I could use to globally set all URL requests in the applicatoin to have User-Agent set to something other than "Java...". just one time when the application starts up
There is a static setDefaultRequestProperty in the URLConnection class. But that is deprecated. What I don't want to do is grep for all lines that say openStream() (in possibly other people's code) and replace it with a openConnection(); getInsputStream();
thanks

Similar Messages

  • Cfhttp user-agent question

    I'm trying to get some information off a page. The info I
    want is on:
    https://www.memberst.com/Programs/SessionDetails.aspx?id=A00277BF-262C-4C2A-8FAA-58AAB8465 589&sid=601275
    and its the section that says x of 10 (last I checked it said
    8 of 10).
    I'm using the following code:
    cfhttp method="get"
    url="https://www.memberst.com/Programs/SessionDetails.aspx?id=A00277BF-262C-4C2A-8FAA-58A AB8465589&sid=601275"
    useragent="Mozilla/4.0">
    </cfhttp>
    <cfset txt=cfhttp.FileContent>
    <cfset re = ([-+]?\d+).*?(of).*?(10)>
    <cfset m = #REFindNoCase(#re#,#txt#,1,"TRUE")#>
    <cfif #ArrayLen(m.pos)# gt 1>
    <cfset int1=#Mid(txt,m.pos[2],m.len[2])#>
    <cfset word1=#Mid(txt,m.pos[3],m.len[3])#>
    <cfset int2=#Mid(txt,m.pos[4],m.len[4])#>
    <cfoutput>
    (#replace(int1,"<" ,"&lt;")#)(#replace(word1,"<"
    ,"&lt;")#)(#replace(int2,"<" ,"&lt;")#)
    </cfoutput>
    </cfif>
    But it seems that the cfhttp is not using the user-agent, as
    I get back
    10px; when I dump out 1 of the locations......
    Any suggestions??

    Anyone have any ideas??? Thoughts??
    "Steve Grosz" <[email protected]> wrote in
    message
    news:fe3jd7$6nl$[email protected]..
    > I'm trying to get some information off a page. The info
    I want is on:
    >
    https://www.memberst.com/Programs/SessionDetails.aspx?id=A00277BF-262C-4C2A-8FAA-58AAB846 5589&sid=601275
    >
    > and its the section that says x of 10 (last I checked it
    said 8 of 10).
    >
    > I'm using the following code:
    >
    > cfhttp method="get"
    >
    url="https://www.memberst.com/Programs/SessionDetails.aspx?id=A00277BF-262C-4C2A-8FAA-58A AB8465589&sid=601275"
    > useragent="Mozilla/4.0">
    > </cfhttp>
    >
    > <cfset txt=cfhttp.FileContent>
    >
    > <cfset re = ([-+]?\d+).*?(of).*?(10)>
    > <cfset m = #REFindNoCase(#re#,#txt#,1,"TRUE")#>
    > <cfif #ArrayLen(m.pos)# gt 1>
    > <cfset int1=#Mid(txt,m.pos[2],m.len[2])#>
    > <cfset word1=#Mid(txt,m.pos[3],m.len[3])#>
    > <cfset int2=#Mid(txt,m.pos[4],m.len[4])#>
    > <cfoutput>
    > (#replace(int1,"<"
    ,"&lt;")#)(#replace(word1,"<"
    > ,"&lt;")#)(#replace(int2,"<" ,"&lt;")#)
    > </cfoutput>
    > </cfif>
    >
    > But it seems that the cfhttp is not using the
    user-agent, as I get back
    > 10px; when I dump out 1 of the locations......
    >
    > Any suggestions??
    >
    >

  • DPM Agent - attaching agent user account question

    Hi there,
    I have a question concerning the attachment of User Agents.
    During the wizard you get asked to fill in a user account which is domain user and local admin. I am working in a big organization and we use service accounts as much as we can. I found out the user account I am to use has insufficient rights, I have
    found out my own AD user account works for the attachment. It is alot of work to have another department in the organisation change the rights of the service account(s).
    I was wondering what purpose does the account you fill in serve. I have seen that the service runs under local system and I can't really find any information about what the user account actually does(right at that moment or later on, doesn't matter).
    I am asking this since I could use my own AD account if its just for authorization during the attachment but not if the account I fill in gets used in a later sitatuation.
    Can anyone clear this up for me?

    Hi,
    The User Account is only used for Installing and attaching the Agent on the remote Server/Client, so best will be to use a Domain Admin user.
    The Agent willalways run unter System Account, so no Special Service Account will be needed.
    Seidl Michael | http://www.techguy.at |
    twitter.com/techguyat | facebook.com/techguyat

  • How to retrieve which user-agent in a java portlet?

    Is there a way to get http user-agent info about which browser requested a page with a portlet from within the java portlet?
    It seems like the request.getHeader() always returns the same value no matter what browser we use.
    Have also tried portletRenderRequest.getOriginalHeader() but this method also returns the same result.
    Does the PPE replace these headers or what..?
    Regards,
    Per A Jorgensen

    Hi Per A Jorgensen,
    I see what you mean. I just deployed a simple portlet which displays the user-agent header property.
    Here are my observations:
    1. If you access the page as user1 from Mozilla, I see the following:
    Browser Agent:      Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.8) Gecko/20050511 RPT-HTTPClient/0.3-3 RPT-HTTPClient/0.3-3
    2. If I now access this page from IE, as user1, then I still see my browser agent as:
    Browser Agent:      Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.8) Gecko/20050511 RPT-HTTPClient/0.3-3 RPT-HTTPClient/0.3-3
    3. If I now access this page from IE, as user2, then i see the following details:
    Browser Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322) RPT-HTTPClient/0.3-3 RPT-HTTPClient/0.3-3
    4. Now I access the same page from Mozilla (after logging out of user1) as user2, I see the following:
    Browser Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322) RPT-HTTPClient/0.3-3 RPT-HTTPClient/0.3-3
    Hmm.. interesting.. it looks like, whoever access the provider first, fixes the user-agent. I need to investigate more into it to find out information as to why this is happening.
    In the mean-time, you can be rest assured that as long as you dont have multiple user's accessing the portlet as the same user, you will get the correct information.
    thanks,
    Harsha

  • Get User Agent (Browser) in Webdynpro 7.01

    Hello Community,
    Some time ago, I already asked this question. Then, we were on NW04. That was the Thread: [Old Thread|Get User Agent (Browser) in Webdynpro; 
    The solution to retrieve the User-Agent was:
    HttpServletRequest request =((IWebContextAdapter) WDWebContextAdapter.getWebContextAdapter()).getHttpServletRequest();
    Now, "IWebContextAdapter" does not work anymore. So I'm in need of another solution. The suggestion of
    HttpServletRequest request = (HttpServletRequest)WDProtocolAdapter.getProtocolAdapter().getRequestObject();
    String value = request.getHeader("<Param Name>");
    in the old thread still throws a "ClassCastException".
    I have also found this Thread: [Other Thread|Get User Agent;
    But here the suggestion is
    HttpServletRequest request = WDProtocolAdapter.getProtocolAdapter().getRequestObject().getProtocolRequest();      
    String userAgent = request.getHeader("User-Agent");
    what doesn't work, because it seems, there is no method "getProtocolRequest()".
    I'd be glad, if anyone would suggest a working way of how to retrieve the User Agent in webdynpro NW 7.0 EHP 1 SPS 04.
    Thank you very much,
    Best regards,
    Christian

    Hi Christian,
    Can you try using this line of code. You can directly get the value of the request object using this.
    WDProtocolAdapter.getProtocolAdapter().getRequestObject().getParameter("parameter_name");
    // There is getParameterMap() method in which you can know what all parameters are available to be captured.
    Map parameterMap =   WDProtocolAdapter.getProtocolAdapter().getRequestObject().getParameterMap();
    I hope this helps.
    Thanks and Regards,
    Pravesh

  • User agent

    Hello everyone. I have bought passport recently. I switch from android device.
    I have question about desktop user agent on the device. Although I have activated it some website still present the mobile form. (for exemple laposte.net)
    I have tried several browser but the problem remains.
    This problem was not present on my android device.
    I assume I have something to set on my blackberry but I don't know what.
    Could you help me to have ALL website with the normal layout please.

    ajitkalu wrote:
    Can any 1 help me to get the user agent for Nokia 5800 xpress music for mozila firefox.
    How about: Mozilla/5.0 (SymbianOS/9.4; U; Series60/5.0 Nokia5800d-1/31.0.008; Profile/MIDP-2.1 Configuration/CLDC-1.1 ) AppleWebKit/413 (KHTML, like Gecko) Safari/413
    Happy to have helped forum with a Support Ratio = 42.5

  • Set a Default User Agent

    I want to set a default user agent (I know how to change it…). Is there a way to do this?

    So my question = is there a possibility to set "Internet Explorer 9" as default User agent string.
    How about taking the tack that Compatibility Settings uses?  Its default is IE7 and it is semi-persistent, apparently lasts until you clear your Cookies for it.  So, what is in the Cookie?  If it says make UAS = IE7  perhaps you could
    change it to be something else?  Alternatively, find out how IE7 becomes that procedure's default and see if there is something in that path which is changeable.  Use ProcMon to investigate these ideas.
    Alternatively, on another tack, look at the implementation of the Microsoft list, in IECompatData.xml.   Some, apparently, have experimented with making custom changes in there.  Then a problem would be that they would have to disable regular
    checking and updating of that list or that again, their modifications would only be semi-persistent, and thus they would have to be prepared to periodically, on an unknown schedule, have to be ready to reassert their modifications.
    FYI
    Robert Aldwinckle

  • Set Default User Agent

    Safari 4.0.3
    Is there a way to Set the Default User Agent to Iphone 3 and the user agent does not revert back when the Safari is restarted.
    Current when I set the user agent to Iphone 3 and then restart the browser the Iphone 3 user agent is not retained. Is there a way to ensure that the Iphone 3 user agent is retained after a restart ?

    So my question = is there a possibility to set "Internet Explorer 9" as default User agent string.
    How about taking the tack that Compatibility Settings uses?  Its default is IE7 and it is semi-persistent, apparently lasts until you clear your Cookies for it.  So, what is in the Cookie?  If it says make UAS = IE7  perhaps you could
    change it to be something else?  Alternatively, find out how IE7 becomes that procedure's default and see if there is something in that path which is changeable.  Use ProcMon to investigate these ideas.
    Alternatively, on another tack, look at the implementation of the Microsoft list, in IECompatData.xml.   Some, apparently, have experimented with making custom changes in there.  Then a problem would be that they would have to disable regular
    checking and updating of that list or that again, their modifications would only be semi-persistent, and thus they would have to be prepared to periodically, on an unknown schedule, have to be ready to reassert their modifications.
    FYI
    Robert Aldwinckle

  • How can you add an extra user agent value for Safari?

    I need to configure Safari to contain an additional User Agent string. This is an IE sample of what I need Safari to add:
    Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; THISIS_ATEST; .NET CLR 1.1.4322)
    I know you can add the Debug menu and change the User Agent but this does not permit you to add an additional string as in the sample above.
    Thank you for your help in advanced.
    Sandra

    Welcome to Apple Discussions
    Not having programming skill, I can't help you with the specifics of your question. However, you may find help here.
    iMac G5 Rev C 20" 2.5gb RAM 250 gb HD/iBook G4 1.33 ghz 1.5gb RAM 40 gb HD   Mac OS X (10.4.8)   LaCie 160gb d2 HD Canon i960 printer, Airport Express (2 units)

  • CSCum97337 - Ise Endpoint Profile is getting degraded based on poorer user agent

    I have searched but I can not find out how to do this 
    Where can I add user-agent strings to an exclusion list ? 
    regards
    Gudmundur

    Check permission of account and account is lockout.
    Also check below link
    http://technet.microsoft.com/en-us/library/hh212922.aspx
    Please remember, if you see a post that helped you please click "Vote As Helpful" and if it answered your question, please click "Mark As Answer"
    Mai Ali | My blog: Technical | Twitter:
    Mai Ali

  • Does Adobe Edge Inspect support a user agent switcher or mobile emulator?

    Hey there,
    Does Adobe Edge Inspect support a user agent switcher or mobile emulator? 
    is there any kind of particular user agent switcher/emulator that is supported?  if so, which?    
    does Adobe have a reliable user agent switcher that supports a tilt option?
    thanks for any help on this

    Please ask your question in the Edge Inspect forum here http://forums.adobe.com/community/edge_inspect. They will be able to help you.

  • Need to log into portal usign a different User-Agent(SPS15 issue)

    Hi,
    we are having an error trying to log portal. We have an application that logs into portal to get the MYSAPSO2 Cookie.
    This applications have in the header the User-Agent "ExtApp".
    Apparently due to changes in SPS15 the page builder becomes more restrictive on the range of browsers that can access portal.
    We´d like to add our own User-Agent.
    Any thoughts on how can this be done.
    Regards
    Fernando

    For anyone interested, the problem was resolved by restarting the OC4J_Security component from the infrastructure tier.
    This poses another question, for newly created users to take effect, does this restart always need to occur?

  • User Agent Stylesheet

    Hello,
    I am having a problem with Safari 5.0.1/Chrome 5.0.3 where the following automagicaly generated style:
    display: table-row-group;
    is being applied to an automatically generated <tbody> tag. The above CSS is causing my table to truncate and wrap the data in an undesirable manner.
    My Question - I cannot find a "user agent stylesheet" that would be causing this and I need to know where this html/css is coming from. Any help is appreciated.

    HI,
    Safari / Preferences - Advanced
    Select: *None selected* from the pop up menu next to *Style Sheet*
    Or from the Develop menu, disable Styles.
    Carolyn

  • I had to change IE's User Agent. However, there are several problems.

    I had to change IE's User Agent. However, there are several problems.
    I wrote the following C# code : 
    RegistryKey reg = Registry.Currentuser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings\5.0\User Agent", true);
    reg.SetValue(null, "Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3");
    So, I have succeeded to change the UserAgent.
    ( ↑ http://esolution.se/whatsmyinfo)
    But, Browser / OS / Is Mobile Device is not changed.
    What should I do to be as follow(Browser User Agent Switcher)?
    Thanks for reading. Sorry immature to English.

    This is more related to ASP.NET and web development as it involves browser agent strings. Please post this question in the ASP.NET forums (http://forums.asp.net ).

  • Internet Explorer 11 - Emulation Document Mode and User Agent String Drop Down Menu Blank

    Hey
    I have a user who has a problem with Internet Explorer 11 where when you go to emulation mode using F12, the Document Mode and User Agent String Drop Down Menu are both blank. On our internal website its works correctly but on all other external websites
    they are both blank.
    I have had a look at the link below but this did not help as it would not recreate some of the registry keys.
    http://answers.microsoft.com/en-us/ie/forum/ie11-iewindows8_1/document-mode-and-user-agent-string-dropdowns/cd34d5f8-7839-4083-af55-05d49ba85190?rtAction=1387560713451
    Charlie

    Hi,
    Please include links to any websites that you are having issues with your questions.
    There are some known reasons why the documentMode dropdown appears blank...
    not all websites though should have the conditions for this.
    f12>Console tab, refresh the page to show suppressed error messages and warnings... (documentMode x-ua toggling is listed)...
    IE11 includes improvements for XSS... to link to internet sites from your intranets you need to add those sites (If you really, really trust them) to the Trusted Sites list.
    the developer console will list blocked xss requests.
    by default IE11 runs in EPM.... in the Internet Zone, while it is not switched on for the intranet zone....
    EPM only allows 64 bit Addons and ActiveX controls to run in the context of an IE tab...
    so its highly likely that one of your Addons is causing the issue.
    the first step in troubleshooting IE issues is to test in noAddons mode.
    Regards.
    Rob^_^

Maybe you are looking for