httpurlconnection

Is it possible to download files like PDF with HttpClient?

 ̄綄美尐妖づ 提交于 2019-12-03 00:31:47
I found some examples here on how to download a file but most of them seem to be using HttpURLConnection. is it possible to download files with HttpClient? Using httpclient is pretty easy. Here's a link to it's tutorial. http://hc.apache.org/httpcomponents-client-ga/tutorial/html/fundamentals.html#d5e43 HttpClient httpclient = new DefaultHttpClient(); HttpGet httpget = new HttpGet(urltofetch); HttpResponse response = httpclient.execute(httpget); HttpEntity entity = response.getEntity(); if (entity != null) { long len = entity.getContentLength(); InputStream inputStream = entity.getContent(); /

HttpURLConnection fail on Android

无人久伴 提交于 2019-12-02 23:13:30
( Solved - see comment below ) I have a class that implements a multipart file upload. The code works on every java client I've tried it on except for Android, and it's the only HTTP request code in my Android app that doesn't play nice with my back end service. The connection responseCode is "-1" so something pretty nasty is going on here. No entries show up in the Apache access or error logs, it seems as if the request is never making it off of the android platform. The code gets right through the connection writes, but hangs on the connection read, times out and then returns. Behavior is

How to send a name value pair Object or content values object using post in android api 23 using HttpUrl connection?

旧巷老猫 提交于 2019-12-02 23:04:43
问题 //Here is what i have tried. // I don't know how to append inputurl and Content values and send this to server using HttpURLConnection. public JSONObject getJsonFromUrl(String inputurl, ContentValues values) { // Making http Request try { URL url=new URL(inputurl); HttpURLConnection connection=(HttpURLConnection)url.openConnection(); connection.setReadTimeout(10000 /* milliseconds */); connection.setConnectTimeout(15000 /* milliseconds */); connection.setRequestMethod("POST"); connection

What could cause socket ConnectException: Connection timed out?

拜拜、爱过 提交于 2019-12-02 21:05:02
We have a Webstart client that communicates to the server by sending serialized objects over HTTPS using java.net.HttpsURLConnection . Everything works perfectly fine on my local machine and on test servers located in our office, but I'm experiencing a very, very strange issue which is only occurring on our production and staging servers (and sporadically at that). The main difference I know of between those servers and the ones in our office is that they are located elsewhere and client-server communication with them is considerably slower, but it worked fine for a long time in production

Android App Strategy for keeping track of a login session

旧时模样 提交于 2019-12-02 18:35:44
I have some PHP script that logs in and returns a JSON array with a session ID if the login was successful. In my app, I want to login at the front page and continue out through the app being logged in. I created a singleton class that holds a session ID (along with a few other fields) received from the JSON from the PHP page. This singleton object's field "session_id" gets checked depending on what the user does. If the user wants to log out, then the session_id just gets set to null thus logging out. I also use the HttpURLConnection library to POST the username/password when logging in. Is

HttpURLConnection, how to sending parameters via post?

拥有回忆 提交于 2019-12-02 16:09:57
问题 String pathToOurFile = "/sdcard/DCIM/Camera/foto.jpg"; String urlServer = "http://server/upload.php"; String lineEnd = "\r\n"; String twoHyphens = "--"; String boundary = "*****"; . . . URL url = new URL(urlServer); connection = (HttpURLConnection) url.openConnection(); // Allow Inputs & Outputs connection.setDoInput(true); connection.setDoOutput(true); connection.setUseCaches(false); // Enable POST method connection.setRequestMethod("POST"); connection.setRequestProperty("Connection", "Keep

“no route to host” on device on getOutputStream() - connected wirelessly

孤街浪徒 提交于 2019-12-02 14:56:43
问题 private String urlPost = "http://192.168.1.66:8080/DataCollectionServlet/"; @Override protected void doWakefulWork(Intent intent) { // https://stackoverflow.com/q/14630255/281545 HttpURLConnection connection = null; try { connection = connection(); w("connection"); // allrigt final OutputStream connOutStream = connection.getOutputStream(); w("GEToUTPUTsTREAM"); // I never see this } catch (IOException e) { e.printStackTrace(); // No route to host } finally { if (connection != null) connection

Cookie management with Java URLConnection

こ雲淡風輕ζ 提交于 2019-12-02 13:27:05
问题 I'm fairly new to android programming and recently achieved a successful HTTP Post request, only to learn that my cookies are not being stored between subsequent Post/Get requests. I looked around the interweb, and found a few examples for Android's Apache client and Java's HttpURLConnection. I was unsuccessful in implementing either method into my current class, so I was wondering if someone with more experience could review my code and offer suggestions. Recap: My initial POST request is

How to wait for Expect 100-continue response in Java using HttpURLConnection

僤鯓⒐⒋嵵緔 提交于 2019-12-02 10:37:25
问题 I am stuck using HttpURLConnection to make a PUT http request to a web-server. I have some code that will make a PUT request just fine, and I can trivially include the 'Expect 100-continue Request Property' in the headers however try as I might I can't seem to make the function wait for the '100 Continue' response from the server before sending the actual http payload. I get the following (from Wireshark) PUT /post/ HTTP/1.1 User-Agent: curl/7.35.0 Accept: */* Content-Type: application/x-www

URLConnection always returns 400 : Bad Request when I try to upload a .wav file

馋奶兔 提交于 2019-12-02 10:13:18
I want to implement some code that does exactly what I accomplish when I execute a CURL command in my Mac's terminal, which is to upload a .wav file to a Server. I already accomplished this for one server before, so my general thinking works (and my code too), ....but now I want to accomplish the same but on a different server. This time I am having trouble and all I get are "400:Bad Request" This is he CURL command I want to do on Android, I have added a "-v" so you can see the verbose of my command. curl -F file=@audio_life.wav 11.2.333.44:14141/transcribe -v Output log in Terminal: * Trying