urlconnection

java.lang.NegativeArraySizeException: -1 downloading file on Android with URLConnection

和自甴很熟 提交于 2021-01-29 08:40:49
问题 so I've tried to implement https://stackoverflow.com/a/1718140/13592426 this function for downloading file in my app, but I didn't succeed, and want to find out why. Here's the code: public class Receiver extends BroadcastReceiver { public static void downloadFile(String url, File outputFile) { try { URL u = new URL(url); URLConnection conn = u.openConnection(); int contentLength = conn.getContentLength(); DataInputStream stream = new DataInputStream(u.openStream()); byte[] buffer = new byte

asynchronous HTTP request in java

泄露秘密 提交于 2021-01-27 03:31:51
问题 How to send asynchronous HTTP GET/POST request in java without waiting/reading response ?I don't want to use any third party libraries .. 回答1: If you're not interested in reading the response at all you can just use URL.openStream() to create a connection and then immediately close the socket (or ignore it and let it time out, if you feel like being mean to the server). This isn't strictly asynchronous, but it will be quite a bit faster than any approach that relies upon fetching and parsing

Http URLConnection wait for inner request

我是研究僧i 提交于 2020-03-23 12:32:12
问题 I am working on a crawling project. When I do a simple URLConnection connection to the website as shown in below: URLConnection conn = new URL(url).openConnection(); BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); The method returns the HTML body correctly. However, the website makes inner requests for some fields. For example, the website fetches the total number of users from a different web service. In the web browser, the total number of users

Invoke the doGet Servlet method from java class

一曲冷凌霜 提交于 2020-02-25 08:51:32
问题 I have a scheduled job class, implements the Quartz Job class, from which I want to invoke a Servlet class that updates a flag in a DB table and then it sends emails to an appropriate emailing list. I get a java.net.ConnectException . Though the servlet is properly invoked by either entering its URL in the browser or by JavaScript in a JSP page. My Java class is the following: public class ExpirationJob implements Job { org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(

Invoke the doGet Servlet method from java class

我只是一个虾纸丫 提交于 2020-02-25 08:51:15
问题 I have a scheduled job class, implements the Quartz Job class, from which I want to invoke a Servlet class that updates a flag in a DB table and then it sends emails to an appropriate emailing list. I get a java.net.ConnectException . Though the servlet is properly invoked by either entering its URL in the browser or by JavaScript in a JSP page. My Java class is the following: public class ExpirationJob implements Job { org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(

java.io.EOFException when sending serialized data to a servlet

对着背影说爱祢 提交于 2020-01-24 12:54:08
问题 I'm tring to upload from my Java local application an object that will include a file to a server. My plan is that a servlet running on tomcat will get the object using the ObjectInputStream in the doGet method. But I get an EOFE xception`. Here is the client code import java.io.*; import java.net.*; public class Client { public static void main(String[] args) throws IOException { FileInputStream inputStream = new FileInputStream("c:\\rafi.txt"); ByteArrayOutputStream output = new

java.io.EOFException when sending serialized data to a servlet

南楼画角 提交于 2020-01-24 12:53:04
问题 I'm tring to upload from my Java local application an object that will include a file to a server. My plan is that a servlet running on tomcat will get the object using the ObjectInputStream in the doGet method. But I get an EOFE xception`. Here is the client code import java.io.*; import java.net.*; public class Client { public static void main(String[] args) throws IOException { FileInputStream inputStream = new FileInputStream("c:\\rafi.txt"); ByteArrayOutputStream output = new

Slow fetching of contents from URL

夙愿已清 提交于 2020-01-07 03:07:13
问题 I am trying to fetch the contents of this url. The contents will get changed for each refresh. I am wrote my code to fetch the content and display it in my app using TextView by a Button Click. But it takes more time ( Minimum 2 seconds , Maximum 6 seconds ) to get the data and display into Textview. So what change do i need in my code to make it efficiant and reduce the delay. Here is my code, ( Fetching done in getData () method using URLConnection method ) public class MainActivity extends

Establishing the URLConnection to another web application does not work with URLConnection .connect()?

对着背影说爱祢 提交于 2020-01-06 20:06:23
问题 Here is the code i am using the open the URLConnection to another webapllication try { URL url = new URL("https://mySecondWebApp/Cart"); HttpsURLConnection conn1 = (HttpsURLConnection) url.openConnection();//line1 conn1 .connect();//line 2 does not establishes the connection conn1.getInputStream();// line 3 works which means that i get control to my app2 in debugger.But this also passes the control to IOException stating error java.io.FileNotFoundException: https://mySecondWebApp/Cart } catch