Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9225691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:38:41+00:00 2026-06-18T04:38:41+00:00

I am using this line to open a stream in my java program but

  • 0

I am using this line to open a stream in my java program but I think I am being blocked because of my real world user agent.

private InputStream is = new URL(a).openStream();  

Where a is a String containing the url.

What is the simplest way I can set the user agent? I have only just learned about them so any further info would be greatly appreciated. For example:
I want to set it to Mozilla/5.0. Do I have to add any further information? If so what should be included and how?
Also, is this strictly allowed as in should I be concerned about any legal issues with regards to setting a user agent? Apologies if that question does not make sense it’s just because I no very little about user agents (basically that programs send them) and I am not sure if you have to b registered or something – I’ve seen that Safari on my Mac adds:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/536.26.17 (KHTML, like Gecko) Version/6.0.2 Safari/536.26.17

Thanks

Ps I have read a similar question on this but I did not understand much from the answer – I am a java beginner and have only just begun trying to open streams to files and urls.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T04:38:43+00:00Added an answer on June 18, 2026 at 4:38 am

    What is the simplest way I can set the user agent?

    URLConnection urlConnection = new URL(a).openConnection();
    urlConnection.addRequestProperty("User-Agent", "Mozilla/5.0");
    InputStream is = urlConnection.getInputStream();
    

    I want to set it to Mozilla/5.0. Do I have to add any further information?

    You can set it to whatever you want. It’s actually a good idea to identify your application, otherwise all Java programs simply send:

    User-Agent: Java/1.7.0_11
    

    Also, is this strictly allowed as in should I be concerned about any legal issues with regards to setting a user agent?

    Nope, you are free to use any user agent as you want. Moreover it’s not illegal to fake user agents. But if a website makes any decisions (especially regarding security) based on User-Agent, it’s so bad as it’s almost illegal 😉 (see: Java – Not getting html code from a URL).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to open Weka from cmd line, using C#. This is the
I am using this line of code to get two data entries from an
I'm using this line to get the beginning time of the first day of
I'm using this line of code to insert a value from an array into
I'm using this CSS to align a line of text (the link) with the
I want to use this line of code: using (ADataContext _dc = new ADataContext(ConnectionString),
I'm using now.js and there's this line that refers to localhost. In order for
I tried using juggernaut cocoa: https://github.com/fpotter/juggernaut-cocoa Added this line to my code: JuggernautClient *client
I have a line, which is a sprite made by using this code CGPoint
I've referenced System.Xml: using System.Xml; Then in this line: XmlDocument xdoc = new XmlDocument();

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.