urlconnection

URLConnection FileNotFoundException for non-standard HTTP port sources

非 Y 不嫁゛ 提交于 2019-11-27 01:01:15
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 down to the URLConnection. It seems as though the URLConnection doesn't recognize the data is HTTP

Java: resume Download in URLConnection

坚强是说给别人听的谎言 提交于 2019-11-26 22:25:32
I wrote a program that downloads some files from some servers. Currently program works properly. But I want to add resume support to it. I'm doing it like this But the result file is corrupted: .... File fcheck=new File(SaveDir+"/"+filename); if(resumebox.isSelected() && fcheck.exists()){ connection.setRequestProperty("Range", "Bytes="+(fcheck.length())+"-"); } connection.setDoInput(true); connection.setDoOutput(true); BufferedInputStream in = new BufferedInputStream (connection.getInputStream()); pbar.setIndeterminate(false); pbar.setStringPainted(true); java.io.FileOutputStream fos ; if

Downloading a portion of a File using HTTP Requests

你。 提交于 2019-11-26 21:38:04
问题 I am trying to download a portion of a PDF file (just for testing "Range" header). I requested the server for the bytes (0-24) in Range but still, instead of getting first 25 bytes (a portion) out of the content, I am getting the full length content. Moreover, instead of getting response code as 206 (partial content), I'm getting response code as 200. Here's my code: public static void main(String a[]) { try { URL url = new URL("http://download.oracle.com/otn-pub/java/jdk/7u21-b11/jdk-7u21

What exactly does URLConnection.setDoOutput() affect?

时光毁灭记忆、已成空白 提交于 2019-11-26 20:02:12
There's setDoOutput() in URLConnection . According to documentation I should Set the DoOutput flag to true if you intend to use the URL connection for output, false if not. Now I'm facing exactly this problem - the Java runtime converts the request to POST once setDoOutput(true) is called and the server only responds to GET requests. I want to understand what happens if I remove that setDoOutput(true) from the code. What exactly will this affect? Suppose I set it to false - what can I do now and what can't I do now? Will I be able to perform GET requests? What is "output" in context of this

Java: how to use UrlConnection to post request with authorization?

青春壹個敷衍的年華 提交于 2019-11-26 18:36:31
I would like to generate POST request to a server which requires authentication. I tried to use the following method: private synchronized String CreateNewProductPOST (String urlString, String encodedString, String title, String content, Double price, String tags) { String data = "product[title]=" + URLEncoder.encode(title) + "&product[content]=" + URLEncoder.encode(content) + "&product[price]=" + URLEncoder.encode(price.toString()) + "&tags=" + tags; try { URL url = new URL(urlString); URLConnection conn; conn = url.openConnection(); conn.setRequestProperty ("Authorization", "Basic " +

Can you explain the HttpURLConnection connection process?

房东的猫 提交于 2019-11-26 18:03:06
I am using HTTPURLConnection to connect to a web service. I know how to use HTTPURLConnection but I want to understand how it works. Basically, I want to know the following: On which point does HTTPURLConnection try to establish a connection to the given URL? On which point can I know that I was able to successfully establish a connection? Are establishing a connection and sending the actual request done in one step/method call? What method is it? Can you explain the function of getOutputStream and getInputStream in layman's term? I notice that when the server I'm trying to connect to is down,

URLConnection with Cookies?

若如初见. 提交于 2019-11-26 17:43:52
问题 I'm trying to make a URLConnection that supports cookies. According to the documentation I can use: CookieManager cookieManager = new CookieManager(); CookieHandler.setDefault(cookieManager); I couldn't get this code to work, then I saw this only works for API 9 (2.3). However, I don't get an error using CookieManager in an older emulator, CookieManager exists, but can't be constructed. Is there any way to make this work for earlier versions? I tried: cookieManager.setAcceptCookie(true);

Apache http client or URLConnection [duplicate]

爱⌒轻易说出口 提交于 2019-11-26 17:30:43
问题 This question already has answers here : URLConnection or HTTPClient : Which offers better functionality and more efficiency? (6 answers) Closed 3 years ago . I need to download a web page on an android app and I am having a hard time deciding whether to use the android apache http client or java's URLConnection. Any thoughts? 回答1: For most things I'd say that HttpClient is the way to go. However there are some situations and edge cases where I'd fall back to a URLConnection . Examples of

Android's HttpURLConnection throws EOFException on HEAD requests

旧街凉风 提交于 2019-11-26 16:59:02
问题 This small code snippet runs fine on my Mac's JVM. Unfortunately it crashes when executed on Android 4.2. import java.net.HttpURLConnection; import java.net.URL; public class App { public static void main( String... arguments ) throws Exception { HttpURLConnection connection = (HttpURLConnection) new URL( "https://github.com" ).openConnection(); connection.setRequestMethod( "HEAD" ); System.out.println( connection.getResponseCode() + "" ); } } If I replace https://github.com with https://www

Can I override the Host header where using java's HttpUrlConnection class?

梦想与她 提交于 2019-11-26 14:41:50
问题 I'm using the following code to open a http connection in java: URL url = new URL("http://stackoverflow.com"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setDoOutput(true); conn.setRequestMethod("GET"); conn.setRequestProperty("Host", "Test:8080"); conn.getOutputStream(); However calling conn.setRequestProperty("Host", "Test:8080") appears to have no effect regardless of what order I call the methods and the Host is reset to the destination server. Is there any