httpurlconnection

Maintain session between HttpUrlConnection Calls (Native/Webview)

六眼飞鱼酱① 提交于 2019-12-05 10:56:46
问题 Let me start with what I desire : I want to make an app which is part native and part webviews . Problem - Maintain a session between native and webview parts. My Approach to handle this: I intend to implement a native login, in which I present the user with two EditTextboxes and a button, the user enters credentials and I post them as JSON to the server. The Server responds with success or false. Based on Success flag I read the header values for this connection and extract the SessionCookie

HttpURLConnection request being hit twice to the server for downloading file

本秂侑毒 提交于 2019-12-05 10:41:57
Following is my android code for downloading file from sever. private String executeMultipart_download(String uri, String filepath) throws SocketTimeoutException, IOException { int count; System.setProperty("http.keepAlive", "false"); // uri="https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcTzoeDGx78aM1InBnPLNb1209jyc2Ck0cRG9x113SalI9FsPiMXyrts4fdU"; URL url = new URL(uri); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.connect(); int lenghtOfFile = connection.getContentLength(); Log.d("File Download", "Lenght of file: " + lenghtOfFile); InputStream

Why does HttpURLConnection.getResponseCode() throws IOException? [duplicate]

空扰寡人 提交于 2019-12-05 09:13:42
This question already has an answer here: HttpURLConnection.getResponseCode() throws IOException when code is known 2 answers I can see that getResponseCode() method is just a getter Method that returns the statusCode already set by the a connect action that happened before. So in this context why does it throw an IOException ? Am i missing something? From javadoc : It will return 200 and 401 respectively. Returns -1 if no code can be discerned from the response (i.e., the response is not valid HTTP). Returns: the HTTP Status-Code, or -1 Throws: IOException - if an error occurred connecting to

Android Http url connection Throwing File Not Found Exception at getInputstream

被刻印的时光 ゝ 提交于 2019-12-05 07:49:16
I am trying to post some json string to a rest sever but I'm getting a java file not found exception at get input stream. Here is my code: package com.muzima.view.sample.activities; import javax.servlet.http.HttpServletResponse; import com.muzima.view.sample.R; import android.app.Activity; import android.content.Intent; import android.os.AsyncTask; import android.os.Bundle; import android.util.Base64; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; import

Volley behind a proxy server

倖福魔咒の 提交于 2019-12-05 07:32:17
I am new to Volley Networking Library (of Android). I have observed that the Request function takes URL as the parameter instead of server name and port. Is there any way for making Volley request to go through a Proxy Server of my choice if I mention the server name and the port? JsonObjectRequest jsObjRequest = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() { I know that we can make use of server and port info while building the URL but is there a way other than this to make sure that the requests go through a Proxy mentioned by us ? For example: How

Java: HTTP PUT with HttpURLConnection

╄→гoц情女王★ 提交于 2019-12-05 05:29:48
How do you do do an HTTP PUT? The class I'm using seems to think it is doing a PUT but the endpoint is treating it as if I did a GET. Am I doing anything wrong? URL url = new URL("https://..."); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setDoOutput(true); conn.setRequestMethod("PUT"); OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream()); writer.write(xmlString); writer.close(); System.out.println(conn.getRequestMethod()); String response = readInputStream(conn.getInputStream()); System.out.println(response); Which is printing: PUT <same

Java : HTTP(S)/WebServices connections through NTLM proxy

拈花ヽ惹草 提交于 2019-12-05 04:51:52
We have a java client side application deployed in our customer (a java application, not an applet). This application checks connectivity with an url.openConnection() and calls web services (with CXF/JAX-WS) through internet. Some of our customer network use proxies to access to the external world. The client side application sets the proxy parameter in java system properties : System.setProperty("proxySet", "true"); //Obsolete ? System.setProperty("http.keepAlive", "false"); System.setProperty("java.net.useSystemProxies", "false"); System.setProperty("https.proxyHost", httpsProxyHost); System

Android POST request using HttpURLConnection

喜欢而已 提交于 2019-12-05 03:16:12
问题 I'm trying to execute post request using HttpURLConnection but don't know how to do it correctly. I can successfully execute request with AndroidAsyncHttp client using following code: AsyncHttpClient httpClient = new AsyncHttpClient(); httpClient.addHeader("Content-type", "application/json"); httpClient.setUserAgent("GYUserAgentAndroid"); String jsonParamsString = "{\"key\":\"value\"}"; RequestParams requestParams = new RequestParams("request", jsonParamsString); httpClient.post("<server url>

android, httpurlconnection error

99封情书 提交于 2019-12-05 02:48:34
I'm running the following test Java script from the Android HttpURLConnection docs : URL url = new URL("http://www.android.com/"); HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); urlConnection.connect(); Eclipse (on my Mac) is telling me there's a system error when I run this in the Android Emulator: 01-13 13:44:32.767: WARN/System.err(1382): java.net.SocketException: Permission denied (Incidentally when I do the equivalent in Objective-C/Cocoa there's no problem at all.) What is the problem? Your application is not allowed to access the network unless it has

Java HttpURLConnection InputStream.close() hangs (or works too long?)

别等时光非礼了梦想. 提交于 2019-12-05 02:32:23
First, some background. There is a worker which expands/resolves bunch of short URLS: http://t.co/example -> http://example.com So, we just follow redirects. That's it. We don't read any data from the connection. Right after we got 200 we return the final URL and close InputStream. Now, the problem itself. On a production server one of the resolver threads hangs inside the InputStream.close() call: "ProcessShortUrlTask" prio=10 tid=0x00007f8810119000 nid=0x402b runnable [0x00007f882b044000] java.lang.Thread.State: RUNNABLE at java.io.BufferedInputStream.fill(BufferedInputStream.java:218) at