httpurlconnection

how to set authorization header with android's httpURLconnection

 ̄綄美尐妖づ 提交于 2019-12-22 08:30:53
问题 I am attempting to connect to my server using basic authentication, but when I set the Authorization header, it causes getInputStream to throw a fileNotFound exception. Here is the relevant code: URL url = new URL(myurl); //set up the connection HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setReadTimeout(10000);//this is in milliseconds conn.setConnectTimeout(15000);//this is in milliseconds String authHeader = getAuthHeader(userID,pass); conn.setRequestMethod("GET"

android, httpurlconnection error

为君一笑 提交于 2019-12-22 04:24:17
问题 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

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

爷,独闯天下 提交于 2019-12-22 04:24:16
问题 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]

How to add parameter in httpurlconnection android

孤街醉人 提交于 2019-12-22 00:35:51
问题 Below code send the images to server successfully. But what I need is have to add an parameter like image description and image date to database. I dont know how to add parameter in HttURLconnection. String fileName = sourceFileUri; HttpURLConnection conn = null; DataOutputStream dos = null; String lineEnd = "\r\n"; String twoHyphens = "--"; String boundary = "*****"; int bytesRead, bytesAvailable, bufferSize; byte[] buffer; int maxBufferSize = 1 * 1024 * 1024; File sourceFile = new File

Server returned HTTP response code: 500 for URL [closed]

坚强是说给别人听的谎言 提交于 2019-12-21 20:19:45
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . java.io.IOException: Server returned HTTP response code: 500 for URL: http://ww .huadt.com.cn/zh-cn/i/l/@357671030745308@V500@0000@AUTOLOW@1@11d590f7$GPRMC,065 48.000,A,3959.8587,N,11617.2447,E,0.00,55.32,210311,,,A*56@@ at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown S urce) at hdt

Stopping silent retries in HttpURLConnection

放肆的年华 提交于 2019-12-21 08:17:44
问题 I'm using HttpURLConnection on Android KitKat to POST some data to a server. The server takes a long time to respond, and the connection is silently retrying 1 to 3 times before timing out. I don't want it to retry, since the server acts on all of the requests, resulting in Bad Things(TM). I've tried System.setProperty("http.keepAlive", "false") before opening the connection, but that doesn't help. 回答1: For POST calls set httpURLConnection.setChunkedStreamingMode(0); and this should fix the

Errorstream in HttpUrlConnection

妖精的绣舞 提交于 2019-12-21 06:59:04
问题 I want to do a POST request to an HTTP Servlet I wrote myself. Good case (HTTP response Code 200) always works fine by using URL.openConnection() method. But when I receive a desired error response code (e.g. 400) then I thought I have to use HttpUrlConnection.getErrorStream(). But the ErrorStream object is null though I am sending data back from the servlet in error case (I want to evaluate this data to generate error messages). This is what my code looks like: HttpURLConnection con = null;

Uploading Image byte array with httpurlconnection and android

混江龙づ霸主 提交于 2019-12-21 05:35:17
问题 I am developing small android application in which I wanted to upload image from my android device to my server. I am using HttpURLConnection for that. I am doing this in following way: Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.arrow_down_float); ByteArrayOutputStream bos = new ByteArrayOutputStream(); bitmap.compress(CompressFormat.JPEG, 100, bos); byte[] data = bos.toByteArray(); connection = (HttpURLConnection) url.openConnection(); connection

HttpURLConnection does not read the whole response

随声附和 提交于 2019-12-21 04:46:54
问题 I use HttpURLConnection to do HTTP POST but I dont always get back the full response. I wanted to debug the problem, but when I step through each line it worked. I thought it must be a timing issue so I added Thread.sleep and it really made my code work, but this is only a temporary workaround. I wonder why is this happening and how to solve. Here is my code: public static InputStream doPOST(String input, String inputMimeType, String url, Map<String, String> httpHeaders, String

Java HttpURLConnection - POST with Cookie

眉间皱痕 提交于 2019-12-21 03:53:42
问题 I´m trying to send a post request with cookies. This is the code: try { String query = URLEncoder.encode("key", "UTF-8") + "=" + URLEncoder.encode("value", "UTF-8"); String cookies = "session_cookie=value"; URL url = new URL("https://myweb"); HttpsURLConnection conn = (HttpsURLConnection) url.openConnection(); conn.setRequestProperty("Cookie", cookies); conn.setRequestMethod("POST"); conn.setDoInput(true); conn.setDoOutput(true); DataOutputStream out = new DataOutputStream(conn