URL.openstream() method can't read from link with &Which “href” value should I use for JavaScript links, “#” or “javascript:void(0)”?Create ArrayList from arrayHow do I call one constructor from another in Java?How do I read / convert an InputStream into a String in Java?Convert HTML + CSS to PDF with PHP?How to get the value from the GET parameters?Linking to an external URL in Javadoc?How can I open a URL in Android's web browser from my application?How to create an HTML button that acts like a link?Redirect from an HTML page
Is it possible to run Internet Explorer on OS X El Capitan?
Why is consensus so controversial in Britain?
Intersection point of 2 lines defined by 2 points each
What is a clear way to write a bar that has an extra beat?
RSA: Danger of using p to create q
Was any UN Security Council vote triple-vetoed?
Convert two switches to a dual stack, and add outlet - possible here?
Could an aircraft fly or hover using only jets of compressed air?
How much RAM could one put in a typical 80386 setup?
What does the "remote control" for a QF-4 look like?
What defenses are there against being summoned by the Gate spell?
Modeling an IP Address
Why is 150k or 200k jobs considered good when there's 300k+ births a month?
Is it possible to do 50 km distance without any previous training?
How is the claim "I am in New York only if I am in America" the same as "If I am in New York, then I am in America?
What's the output of a record needle playing an out-of-speed record
Do I have a twin with permutated remainders?
Which country benefited the most from UN Security Council vetoes?
I'm flying to France today and my passport expires in less than 2 months
tikz convert color string to hex value
Is it possible to record a short contained sound no longer than 60 milliseconds?
Replacing matching entries in one column of a file by another column from a different file
Approximately how much travel time was saved by the opening of the Suez Canal in 1869?
How does quantile regression compare to logistic regression with the variable split at the quantile?
URL.openstream() method can't read from link with &
Which “href” value should I use for JavaScript links, “#” or “javascript:void(0)”?Create ArrayList from arrayHow do I call one constructor from another in Java?How do I read / convert an InputStream into a String in Java?Convert HTML + CSS to PDF with PHP?How to get the value from the GET parameters?Linking to an external URL in Javadoc?How can I open a URL in Android's web browser from my application?How to create an HTML button that acts like a link?Redirect from an HTML page
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I have a link to a .csv which looks like this:
http://website.com/data.csv?since=2019-03-21T00:00Z&sensor=xxx
My method get this link as URL
BufferedReader in = new BufferedReader(new InputStreamReader(URL.openStream()));
The problem is that it is not properly downloading .csv. I have realized that if I add 'amp;' after & it works properly. Is there any easy way to work this out?
java html spring-boot url
add a comment |
I have a link to a .csv which looks like this:
http://website.com/data.csv?since=2019-03-21T00:00Z&sensor=xxx
My method get this link as URL
BufferedReader in = new BufferedReader(new InputStreamReader(URL.openStream()));
The problem is that it is not properly downloading .csv. I have realized that if I add 'amp;' after & it works properly. Is there any easy way to work this out?
java html spring-boot url
add a comment |
I have a link to a .csv which looks like this:
http://website.com/data.csv?since=2019-03-21T00:00Z&sensor=xxx
My method get this link as URL
BufferedReader in = new BufferedReader(new InputStreamReader(URL.openStream()));
The problem is that it is not properly downloading .csv. I have realized that if I add 'amp;' after & it works properly. Is there any easy way to work this out?
java html spring-boot url
I have a link to a .csv which looks like this:
http://website.com/data.csv?since=2019-03-21T00:00Z&sensor=xxx
My method get this link as URL
BufferedReader in = new BufferedReader(new InputStreamReader(URL.openStream()));
The problem is that it is not properly downloading .csv. I have realized that if I add 'amp;' after & it works properly. Is there any easy way to work this out?
java html spring-boot url
java html spring-boot url
asked Mar 21 at 23:03
sebaokasebaoka
478
478
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I have found the solution: https://www.mkyong.com/java/java-httpurlconnection-follow-redirect-example/
public URL getFinalUrl(URL url)
try
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(5000);
conn.addRequestProperty("Accept-Language", "en-US,en;q=0.8");
conn.addRequestProperty("User-Agent", "Mozilla");
conn.addRequestProperty("Referer", "google.com");
boolean redirect = false;
int status = conn.getResponseCode();
if (status != HttpURLConnection.HTTP_OK)
if (status == HttpURLConnection.HTTP_MOVED_TEMP
String newUrl = null;
if (redirect)
// get redirect url from "location" header field
newUrl = conn.getHeaderField("Location");
// get the cookie if need, for login
String cookies = conn.getHeaderField("Set-Cookie");
// open the new connnection again
conn = (HttpURLConnection) new URL(newUrl).openConnection();
conn.setRequestProperty("Cookie", cookies);
conn.addRequestProperty("Accept-Language", "en-US,en;q=0.8");
conn.addRequestProperty("User-Agent", "Mozilla");
conn.addRequestProperty("Referer", "google.com");
System.out.println(newUrl);
return new URL(newUrl);
catch (IOException ioe)
System.out.println("Wrong sensor URL");
return null;
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55290511%2furl-openstream-method-cant-read-from-link-with%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I have found the solution: https://www.mkyong.com/java/java-httpurlconnection-follow-redirect-example/
public URL getFinalUrl(URL url)
try
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(5000);
conn.addRequestProperty("Accept-Language", "en-US,en;q=0.8");
conn.addRequestProperty("User-Agent", "Mozilla");
conn.addRequestProperty("Referer", "google.com");
boolean redirect = false;
int status = conn.getResponseCode();
if (status != HttpURLConnection.HTTP_OK)
if (status == HttpURLConnection.HTTP_MOVED_TEMP
String newUrl = null;
if (redirect)
// get redirect url from "location" header field
newUrl = conn.getHeaderField("Location");
// get the cookie if need, for login
String cookies = conn.getHeaderField("Set-Cookie");
// open the new connnection again
conn = (HttpURLConnection) new URL(newUrl).openConnection();
conn.setRequestProperty("Cookie", cookies);
conn.addRequestProperty("Accept-Language", "en-US,en;q=0.8");
conn.addRequestProperty("User-Agent", "Mozilla");
conn.addRequestProperty("Referer", "google.com");
System.out.println(newUrl);
return new URL(newUrl);
catch (IOException ioe)
System.out.println("Wrong sensor URL");
return null;
add a comment |
I have found the solution: https://www.mkyong.com/java/java-httpurlconnection-follow-redirect-example/
public URL getFinalUrl(URL url)
try
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(5000);
conn.addRequestProperty("Accept-Language", "en-US,en;q=0.8");
conn.addRequestProperty("User-Agent", "Mozilla");
conn.addRequestProperty("Referer", "google.com");
boolean redirect = false;
int status = conn.getResponseCode();
if (status != HttpURLConnection.HTTP_OK)
if (status == HttpURLConnection.HTTP_MOVED_TEMP
String newUrl = null;
if (redirect)
// get redirect url from "location" header field
newUrl = conn.getHeaderField("Location");
// get the cookie if need, for login
String cookies = conn.getHeaderField("Set-Cookie");
// open the new connnection again
conn = (HttpURLConnection) new URL(newUrl).openConnection();
conn.setRequestProperty("Cookie", cookies);
conn.addRequestProperty("Accept-Language", "en-US,en;q=0.8");
conn.addRequestProperty("User-Agent", "Mozilla");
conn.addRequestProperty("Referer", "google.com");
System.out.println(newUrl);
return new URL(newUrl);
catch (IOException ioe)
System.out.println("Wrong sensor URL");
return null;
add a comment |
I have found the solution: https://www.mkyong.com/java/java-httpurlconnection-follow-redirect-example/
public URL getFinalUrl(URL url)
try
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(5000);
conn.addRequestProperty("Accept-Language", "en-US,en;q=0.8");
conn.addRequestProperty("User-Agent", "Mozilla");
conn.addRequestProperty("Referer", "google.com");
boolean redirect = false;
int status = conn.getResponseCode();
if (status != HttpURLConnection.HTTP_OK)
if (status == HttpURLConnection.HTTP_MOVED_TEMP
String newUrl = null;
if (redirect)
// get redirect url from "location" header field
newUrl = conn.getHeaderField("Location");
// get the cookie if need, for login
String cookies = conn.getHeaderField("Set-Cookie");
// open the new connnection again
conn = (HttpURLConnection) new URL(newUrl).openConnection();
conn.setRequestProperty("Cookie", cookies);
conn.addRequestProperty("Accept-Language", "en-US,en;q=0.8");
conn.addRequestProperty("User-Agent", "Mozilla");
conn.addRequestProperty("Referer", "google.com");
System.out.println(newUrl);
return new URL(newUrl);
catch (IOException ioe)
System.out.println("Wrong sensor URL");
return null;
I have found the solution: https://www.mkyong.com/java/java-httpurlconnection-follow-redirect-example/
public URL getFinalUrl(URL url)
try
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(5000);
conn.addRequestProperty("Accept-Language", "en-US,en;q=0.8");
conn.addRequestProperty("User-Agent", "Mozilla");
conn.addRequestProperty("Referer", "google.com");
boolean redirect = false;
int status = conn.getResponseCode();
if (status != HttpURLConnection.HTTP_OK)
if (status == HttpURLConnection.HTTP_MOVED_TEMP
String newUrl = null;
if (redirect)
// get redirect url from "location" header field
newUrl = conn.getHeaderField("Location");
// get the cookie if need, for login
String cookies = conn.getHeaderField("Set-Cookie");
// open the new connnection again
conn = (HttpURLConnection) new URL(newUrl).openConnection();
conn.setRequestProperty("Cookie", cookies);
conn.addRequestProperty("Accept-Language", "en-US,en;q=0.8");
conn.addRequestProperty("User-Agent", "Mozilla");
conn.addRequestProperty("Referer", "google.com");
System.out.println(newUrl);
return new URL(newUrl);
catch (IOException ioe)
System.out.println("Wrong sensor URL");
return null;
answered Mar 21 at 23:54
sebaokasebaoka
478
478
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55290511%2furl-openstream-method-cant-read-from-link-with%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown