urlconnection

Reading Result from HTTP Request in Android

本小妞迷上赌 提交于 2019-12-23 02:26:53
问题 I need to read the response message retrieved after connecting to an online PHP script. This script returns the following: {"success":1,"innerResult":[{"username":"raafat","password":"123"}]} I just need to read the success value from this message. I tried HTTP Request: private class GetPersonDetails extends AsyncTask<String, String, String> { //Activity act; Context mContext; ProgressDialog progressDialog; @Override /* public void onPreExecute() { progressDialog = new ProgressDialog(mContext

Connection to a URL from within an applet using Apache's HttpClient vs using the JDK's URLConnection

筅森魡賤 提交于 2019-12-21 17:47:44
问题 In the following code, I have verified that connecting to a URL from within an applet preserves the browser's session if JDK's URLConnection class is used. However, this is not the case if Apache's HttpClient library is used. Does anyone know why? Alternatively, is there a way for me to set the connection instance to be used by an HttpClient instance? import java.applet.Applet; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net

How does URLConnection.setUseCaches() work in practice?

ぐ巨炮叔叔 提交于 2019-12-20 10:28:42
问题 I have an Applet which is loading images over a http connection using URLConnection. I am setting setUseCaches(true) for all connections, but still not seeing any caching behavior. My image's HTTP headers have reasonable cache settings. If you look at bug 4528599 there is this rather mysterious statement: The current version (1.3.1) of Java Plug-In only checks the browser cache for files whose names end in .jar or .class. I have been told that for Java Plug-In 1.4 the browser cache will be

URLConnection is not allowing me to access data on Http errors (404,500,etc)

末鹿安然 提交于 2019-12-20 09:46:15
问题 I am making a crawler, and need to get the data from the stream regardless if it is a 200 or not. CURL is doing it, as well as any standard browser. The following will not actually get the content of the request, even though there is some, an exception is thrown with the http error status code. I want the output regardless, is there a way? I prefer to use this library as it will actually do persistent connections, which is perfect for the type of crawling I am doing. package test; import java

Get modified date of web resource in Java

橙三吉。 提交于 2019-12-20 04:19:31
问题 How do you get the modified date of a web resource in Java? URL url = new URL(urlString); URLConnection connection = url.openConnection(); connection.connect(); // What now? 回答1: URL url = new URL(urlString); URLConnection connection = url.openConnection(); connection.connect(); long time = connection.getLastModified(); Javadoc Returns the value of the last-modified header field. The result is the number of milliseconds since January 1, 1970 GMT. 来源: https://stackoverflow.com/questions

java.io.IOException: Server returned HTTP response code: 500

China☆狼群 提交于 2019-12-17 23:28:08
问题 I'm facing this problem with Java. I want to get some HTML informations from a URL. This code was working for so long, but suddenly, it stopped working. When I access this URL using the browser, it opens with no problem. The code: URL site = new URL(this.url); java.net.URLConnection yc = site.openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream())); String inputLine; String objetivo = "<td height=\"28\" colspan=\"2\""; while ((inputLine = in

Calling a Servlet from a Java application

点点圈 提交于 2019-12-17 09:59:50
问题 I want to call a Servlet from a Java application. The problem is, that the call seems not to reach the Servlet. I do not get any error, but do not reach the first output "doPost" in the Servlet. If I open the URL in a web browser, I got - of course - the error that GET is not supported etc., but at least I see, that something happens. I use the following code (the ActionPackage class only holds a Vector of parameters and is Serializable): Java application: ActionPackage p = new ActionPackage(

URLConnection FileNotFoundException for non-standard HTTP port sources

Deadly 提交于 2019-12-17 06:38:09
问题 I was trying to use the Apache Ant Get task to get a list of WSDLs generated by another team in our company. They have them hosted on a weblogic 9.x server on http://....com:7925/services/. I am able to get to the page through a browser, but the get task gives me a FileNotFoundException when trying to copy the page to a local file to parse. I was still able to get (using the ant task) a URL without the non-standard port 80 for HTTP. I looked through the Ant source code, and narrowed the error

Image writing over URLConnection

随声附和 提交于 2019-12-13 14:15:09
问题 I am trying to write an image over an HttpURLConnection. I know how to write text but I am having real problems trying to write an image I have succeeded in writing to the local HD using ImageIO: But I am trying to write Image by ImageIO on url and failed URL url = new URL(uploadURL); connection = (HttpURLConnection) url.openConnection(); connection.setDoOutput(true); connection.setRequestMethod("POST"); connection.setDoInput(true); connection.setUseCaches(false); connection

How to get a proxy-less connection in Java?

不问归期 提交于 2019-12-13 12:06:05
问题 How do I avoid going through the ProxySelector when making a connection with URLConnection or rather how to get a connection guaranteed free of whatever proxies Java knows about ? I thought this was what Proxy.NO_PROXY was for. Quoting from the Javadoc: A proxy setting that represents a DIRECT connection, basically telling the protocol handler not to use any proxying Yet such a connection will still go through the ProxySelector. I don't get it ?? I've made a small test to prove my point: