urlconnection

URLConnection getContent() return null

。_饼干妹妹 提交于 2019-12-13 08:38:13
问题 I use the following method to get a bitmap input stream: private InputStream getInputStream(String urlString) throws MalformedURLException, IOException { URL url = new URL(urlString); URLConnection connection; connection = url.openConnection(); //connection.setUseCaches(true); Object response = connection.getContent(); if (!(response instanceof InputStream)) throw new IOException("URLConnection response is not instanceof InputStream"); return (InputStream)response; } It works great on Android

Get Progress of HTTPRequest in Java

心不动则不痛 提交于 2019-12-13 05:24:19
问题 i got a java method which returns the response of the website in a string. Now i want to add the possibility to track the progress of this request. I know i can calculate it via (contenLength/readBytes) *100. But i am not sure how to retrieve this information properly and update the progress everytime it changes. My current method looks like this: public String executePost(URL url) { StringBuffer sb = new StringBuffer(); int readBytes = 0; int contentLength = 0; int progress = 0; try { String

Android: URL Connection accessing to website

纵然是瞬间 提交于 2019-12-13 03:32:58
问题 I am extracting details from a website using the below code. Code: private class FetchAllData extends AsyncTask<Void, Void, Void> { @Override protected void onPreExecute() { super.onPreExecute(); Utilities.custom_toast(CurrentResult.this, "Refreshing", "gone!", "short", "vertical"); } @Override protected Void doInBackground(Void... params) { try { //String urlX = URL1 + "?x=" + new Random().nextInt(100000); //Method1 String urlX = URL1 //Method2; URL url = new URL(""+ urlX); URLConnection con

Download gif from given URL

只愿长相守 提交于 2019-12-13 02:33:55
问题 I'm trying to download GIF from given Url but there is a problem. I'm stuck here and don't know the correct way to download this file. How to repair this? I have sample url: http://i1.kwejk.pl/k/obrazki/2015/02/6f0239004a643dbd9510ebda5a6f22b3.gif My code: try{ System.out.println(this.adressToGif); URL url = new URL(urltoGif); URLConnection conn = url.openConnection(); //conn.connect(); InputStream is = conn.getInputStream(); //IT crashes here and jumps to catch() BufferedInputStream bis =

Java Webstart and URLConnection caching API

半城伤御伤魂 提交于 2019-12-12 07:40:07
问题 The description of the URLConnection caching API states as the last sentence: There is no default implementation of URLConnection caching in the Java 2 Standard Edition. However, Java Plugin and Java WebStart do provide one out of the box. Where can I find more information about the Webstart ResponseCache? Which Versions of Webstart on which platforms activate Caching? In which cases is it active? Only HTTP Get? Can it be configured? Is the sourcecode available? Background: Case 1 With

Java URLConnection returns null for valid URL

*爱你&永不变心* 提交于 2019-12-12 04:33:38
问题 I've been collecting stock market data for a project, and have been doing so for the past few months. However, as of a couple of days ago the URLConnection I've been using to download data from Yahoo has been null, despite having made no changes and it having worked perfectly before that. The URL from Yahoo downloads a csv file which I read and print out, and the URL is valid and works if I go to it on my browser, yet when I connect to it in my code, the URLConnection is null. Trying with

Java HTTP Request Fail

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 20:29:50
问题 I'm doing one java query with http on some search engines and here is the code of two classes: public EventSearch(){ btsearch.addActionListener(this); } public void actionPerformed(ActionEvent e){ if(e.getSource()==btsearch){ try { HttpRequest http = new HttpRequest(CatchQuery()); } catch (IOException e1) { JOptionPane.showMessageDialog(null, "HTTP request failure."); } this.dispose(); } } public String CatchQuery(){ query=txtsearch.getText(); return query; } and public class HttpRequest

HTTP Conditional GET

感情迁移 提交于 2019-12-11 19:13:51
问题 I'm trying to check if a file has been modified after a given date. I found this I'm trying to use Java's HttpURLConnection to do a "conditional get", but I never get a 304 status code. which seemed like what I needed. But if I try: URLConnection connection = new URL("http://cdn3.sstatic.net/stackoverflow/img/favicon.ico").openConnection(); connection.setRequestProperty("If-Modified-Since", "Wed, 06 Oct 2010 02:53:46 GMT"); System.out.println(connection.getHeaderFields()); The output is:

Android URLConnection does only work in wifi, not with 3g

情到浓时终转凉″ 提交于 2019-12-11 08:38:22
问题 I have written an app which uses an URLConnection to get a .html file. Everything works fine over wifi. But over 3g the file is not returned correctly. When i try to access the website via the browser it works fine. Anyone has a suggestion? Update: Here is my code: URL downloadUrl; URLConnection downloadConnection; InputStream inputStream; byte[] inputBytes; String[] output; private void downloadSource(String pUrl) { try { downloadUrl = new URL(pUrl); downloadConnection = downloadUrl

In java how can I connect to https sites without worrying about security certificates

走远了吗. 提交于 2019-12-11 07:33:01
问题 When I try to connect to https website like follows: StringBuilder sb = new StringBuilder(); URL oracle = new URL("https://company.com"); URLConnection yc = oracle.openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream())); String inputLine; while ((inputLine = in.readLine()) != null) sb.append(inputLine); in.close(); return sb.toString(); I get sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath