httpurlconnection

HttpURLConnection GET request getting 400 Bad Request

℡╲_俬逩灬. 提交于 2019-11-28 05:10:48
问题 I am trying to do a GET request with some parameters in Java using HttpURLConnection. Everytime I do this however, I get a 400: Bad Request each time. What do I need to change to make it work? String url = "http://www.awebsite.com/apath?p1=v1&p2=v2&p3=v3"; HttpURLConnection conn = (HttpURLConnection)new URL(url).openConnection(); conn.setDoInput(true); conn.setDoOutput(false); conn.setUseCaches(false); conn.setRequestMethod("GET"); conn.setRequestProperty("Host", "www.awebsite.com"); conn

HttpURLConnection java.io.FileNotFoundException

不羁岁月 提交于 2019-11-28 04:29:28
The code below works great if I connect to what seems to be Apache servers, however when I try to connect to my .Net server it throws an error. I am guessing it is a header requirement, but I can not seem to get a successful response no matter what I try. public String Download(String Url) { String filepath=null; try { //set the download URL, a url that points to a file on the internet //this is the file to be downloaded URL url = new URL(Url); //create the new connection HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); //set up some things on the connection

Why would URLConnection timeout after 6+ minutes instead of 5 seconds?

半世苍凉 提交于 2019-11-28 03:45:40
问题 I am copying this method verbatim from my application, which isn't complete yet but it does attempt to provide me with a timeout stack trace if things don't go smoothly: protected boolean isHttpAlive() { boolean isHttpOk = false; HttpURLConnection httpConnection = null; try { URL gurl = new URL("http://www.amazon.com/"); URLConnection connection = gurl.openConnection(); connection.setConnectTimeout(5 * 1000); // 5 seconds! httpConnection = (HttpURLConnection) connection; int responseCode =

Java HTTPUrlConnection timeout does not work

a 夏天 提交于 2019-11-28 03:09:41
问题 I've written a programm that opens a httpurlconnection to a website through random proxies. My httpurlconnection is called conn . Now I know, that some of those proxies might be too slow, so i've set the timeout of the connection to 40000 milliseconds with conn.setConnectTimeout(40000) and conn.setReadTimeout(40000) . After doing so, i got this code: long diff = 0; long starttime = 0; long endtime = 0; try { starttime = System.currentTimeMillis(); conn.connect(); endtime = System

Android Https Status code -1

会有一股神秘感。 提交于 2019-11-28 01:39:26
问题 I'm connecting to a web server from my android application via HttpsUrlConnection or HttpUrlConnection depending on settings. For now I didn't have any kind of problem, but yesterday I start getting http/https status response -1 . There is no way the web server return me this even if there is some kind of error. The server which I'm connection to is designed to return errorCode and errorString when there is some kind of problem. Here is the code I'm using,but I don't think the problem is here

Android: Trying to get data from youtube api

纵饮孤独 提交于 2019-11-27 21:57:47
问题 I'm attempting to get data from http://gdata.youtube.com/feeds/api/standardfeeds/recently_featured?&start-index=1&max-results=15&v=2 and print the titles of the videos, but I get an exception in the line int responseCode = httpConnection.getResponseCode(); what's the problem? Any other way to get this data? My code: URL url; try { String featuredFeed = "http://gdata.youtube.com/feeds/api/standardfeeds/recently_featured?&start-index=1&max-results=15&v=2"; url = new URL(featuredFeed);

Android HttpURLConnection throwing EOFException

亡梦爱人 提交于 2019-11-27 21:41:33
问题 Here's the question in simplest way. I create a HTTPS connection to my server through proxy using HttpUrlConnection Object. My proxy closes the connection but my code still tries to reuse the same connection. And so I get EOFException. How do I handle such cases? 回答1: I'd recommend disabling the http.keepalive system property. The performance section of the documentation indicates that socket connections will be reused when possible. It sounds like it is trying to reuse the connection, but

Java HttpURLConnection doesn't connect when I call connect()

一笑奈何 提交于 2019-11-27 21:37:43
I'm trying to write a program to do automated testing on my webapp. To accomplish this, I open up a connection using HttpURLConnection. One of the pages that I'm trying to test performs a 302 redirect. My test code looks like this : URL currentUrl = new URL(urlToSend); HttpURLConnection connection = (HttpURLConnection) currentUrl.openConnection(); connection.connect(); system.out.println(connection.getURL().toString()); So, let's say that urlToSend is http://www.foo.com/bar.jsp , and that this page redirects you to http://www.foo.com/quux.jsp . My println statement should print out http://www

Android HTTPUrlConnection : how to set post data in http body?

你离开我真会死。 提交于 2019-11-27 20:38:51
问题 I've already created my HTTPUrlConnection : String postData = "x=val1&y=val2"; URL url = new URL(strURL); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); conn.setRequestProperty("Set-Cookie", sessionCookie); conn.setRequestProperty("Content-Length", "" + Integer.toString(postData.getBytes().length)); // How to add postData as http body? conn.setUseCaches(false); conn

All trusting HostnameVerifier causes SSL errors with HttpURLConnection

允我心安 提交于 2019-11-27 18:51:18
问题 I'm using HttpURLConnection to connect to SSL sites. Occasionally these use self signed certificates / otherwise badly behaved SSL so I have a mode where these an be accessed. I'm using the typical code recommended many places online: // Create a trust manager that does not validate certificate chains TrustManager[] trustAllCerts = new TrustManager[]{ new X509TrustManager() { public java.security.cert.X509Certificate[] getAcceptedIssuers() { return null; } public void checkClientTrusted(java