httpurlconnection

HTTP 403 while executing a PUT request

℡╲_俬逩灬. 提交于 2019-12-10 11:46:26
问题 I am creating a django rest api, and I'm trying to send JSON data via PUT request from an Android device, using HttpUrlConnection. URL url = new URL(myurl); conn = (HttpURLConnection) url.openConnection(); conn.setReadTimeout(10000 /* milliseconds */); conn.setConnectTimeout(15000 /* milliseconds */); conn.setRequestMethod("PUT"); conn.setDoInput(true); conn.setDoOutput(true); conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); conn.setRequestProperty("Accept",

HttpURLConnection worked fine in Android 2.x but NOT in 4.1: No authentication challenges found

橙三吉。 提交于 2019-12-10 06:01:32
问题 I have some typical codes which used HttpURLConnection to get a file with an URL. They worked fine in android 1.x and 2.x. But failed in Android 4.1! I searched on the web but found little similar information. Would anybody please help to investigate this issue? private String mURLStr; private HttpURLConnection mHttpConnection; ... url = new URL(mURLStr); ... mHttpConnection = (HttpURLConnection) url.openConnection(); mHttpConnection.setDoOutput(true); mHttpConnection.setRequestMethod("GET");

HttpURLConnection PUT to Google Cloud Storage giving error 403

时间秒杀一切 提交于 2019-12-10 02:06:43
问题 I tried to upload a file to Google Cloud Storage using XML API. I have the right GoogleAccessId, expiry date and signature generated for each upload. The strange thing is that I can PUT file using Postman (application for Chrome), so I'm sure that the URL is ok. I just cannot PUT it using my Android Java program (it returns to me 403 error). The source code performing upload is here (it base on this one: https://cloud.google.com/storage/docs/access-control#Signing-Strings): URL url;

Prestashop and web service(Restful), HttpURLConnection, BufferedReader

寵の児 提交于 2019-12-09 23:39:10
问题 I want to access the resources of a site created by prestashop via restful web services, which I enter the URL you must enter a key (that is generated by prestashop when we create a restful web service) in the field of username. so I am trying to read a xml string: <?xml version="1.0" encoding="UTF-8"?> <prestashop> <manufacturers> <manufacturer id="1" xlink:href="http://127.0.0.1/test/api/manufacturers/1" /> <manufacturer id="2" xlink:href="http://127.0.0.1/test/api/manufacturers/2" /> <

IllegalArgumentException at URLPermission in jre8

一个人想着一个人 提交于 2019-12-09 23:31:32
问题 when i run the code below, -in an Applet on JRE8, on the line con.getInputStream() it throws the exception -in an Applet on JRE7 or JRE6 it does not throws. -in a Desktop app on any JRE it does not throws. when i remove the lines starts with setRequestPropery , it does not throws the exception on any JRE. URLConnection con = new URL(adress).openConnection(); con.setDoOutput(true); con.setDoInput(true); con.setUseCaches(false); con.setRequestProperty("Content-Type", "application/octet-stream")

Java, HttpURLConnection and setting the content length

拜拜、爱过 提交于 2019-12-09 14:38:19
问题 I'm setting the length of the content in my HttpURLConnection, for a PUT. urlConnection.setRequestProperty("Content-Length", "" + responseJSONArray.toString(2).getBytes("UTF8").length); The actual number of bytes is 74. However, when I query the content length of urlConnection I'm returned -1 . Why is that? And why are lengths not equal (given that I set this)? I must set the content-length because I'm receiving a 411 response from the server. (Also, in the Sun examples I've seen the second

HttpURLConnection doing a get request even after setDoOutput(true), setRequestMethod(“POST”) setRequestProperty(\"Content

北城以北 提交于 2019-12-09 07:45:32
Here is the code: String Surl = "http://mysite.com/somefile"; String charset = "UTF-8"; query = String.format("param1=%s&param2=%s", URLEncoder.encode("param1", charset), URLEncoder.encode("param2", charset)); HttpURLConnection urlConnection = (HttpURLConnection) new URL(Surl + "?" + query).openConnection(); urlConnection.setRequestMethod("POST"); urlConnection.setDoOutput(true); urlConnection.setUseCaches(false); urlConnection.setAllowUserInteraction(false); urlConnection.setRequestProperty("Accept-Charset", charset); urlConnection.setRequestProperty("User-Agent","<em>Android</em>");

What is the difference between httpconnection on J2ME and HttpUrlConnection on Android (http error 401)

佐手、 提交于 2019-12-09 06:36:17
问题 I connect to two servers (PROD is https, test server is http) on my applicaitons. on J2ME: I can connect to this two servers without a problem. on Android I can't connect to test-server. When connection is http, if I dont use setChunkedStreamingMode , I cant get responseCode(StringIndexOutOfBoundsException); if I use setChunkedStreamingMode , response code is 401 . What should I do, where is my fault?? Here is my android code, Also if you want to see J2me code, I can add it, too. URL url =

HTTP responses with code 3xx and empty 'Location' header

回眸只為那壹抹淺笑 提交于 2019-12-09 03:46:23
问题 I'm connecting to URLs with Java ( HttpURLConnection ). I have noticed that in some cases, the response code is 3xx but the 'Location' header is empty. How does a client browser know where to redirect after receiving this kind of HTTP response? Thanks 回答1: Not all 3xx replies can redirect automatically. 300 provides multiple URLs in the response body, not in the Location header. The client/user has to decide which one to retrieve next. 301 , 302 , 303 , and 307 provide a Location only if the

Posting a large file in Android

我只是一个虾纸丫 提交于 2019-12-08 22:31:14
问题 I sometimes get an OutOfMemoryError when posting a large file in Android. This is the code I'm using. Am I doing something wrong? HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("POST"); con.setDoInput(true); con.setDoOutput(true); ostream = new DataOutputStream(con.getOutputStream()); byte[] buffer = new byte[1536]; int count; while ((count = fileInput.read(buffer)) != -1) { ostream.write(buffer, 0, count); // This sometimes causes OutOfMemoryError }