httpurlconnection

Android setRequestProperty in a url.openConnection()

穿精又带淫゛_ 提交于 2019-12-11 01:54:30
问题 I have an Android app that need to set a requestproperty in a connection. Here is my code: URL url = new URL(sUrl); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestProperty("cookie", cookievalue); connection.connect(); When I call the setRequestProperty method it launch the exception: java.lang.IllegalStateException: Cannot set request property after connection is made Is there a way to create the connection to the file without using the url

Retrofit & HTTP Patch

限于喜欢 提交于 2019-12-11 01:39:18
问题 So I want to make a PATCH request using Retrofit but currently I cannot add okhttp to my classpath. When I attempt to make a PATCH request I get the stack trace below. Is there any other way I could use Patch without using okhttp? java.net.ProtocolException at java.net.HttpURLConnection.setRequestMethod(HttpURLConnection.java:644) at retrofit.client.UrlConnectionClient.prepareRequest(UrlConnectionClient.java:50) at retrofit.client.UrlConnectionClient.execute(UrlConnectionClient.java:37) at

How do I find where an HttpURLConnection is trying to redirect me to?

久未见 提交于 2019-12-11 01:05:07
问题 I have an HttpURLConnection that I do not what to follow redirects, however if a redirect appears I want to know where I would get redirected to. There doesn't seem to be a method of HttpURLConnection that will show me that, is there any way I can get that information? 回答1: Get the Header "Location", it contains the URL where you are redirected. Look at the HTTP spec for all the details 回答2: First turn of redirect follows: conn.setInstanceFollowRedirects(false); conn being your HTTPConnection

SignalR connection hangs, calls client ~30 seconds later

只愿长相守 提交于 2019-12-10 19:15:02
问题 I'm using the latest SignalR from NuGet in a MVC4 site. Using the sample hub code (or any code), I'm getting some weird connection problems. Everything loads fine, SignalR makes the negotiate call and logs "EventSource Connected" and returns connectionid. The problem starts when it makes the signalR/connect request with any transport. It returns a 200 response with the proper headers but the connection hangs open. If the called hub method executes a method on Caller or Clients , it does not

Android HTTPUrlConnection POST

女生的网名这么多〃 提交于 2019-12-10 18:44:51
问题 I am using HttpURLConnection to send data to a server via POST. I set the headers then get the output stream and write 5 bytes of data ("M=005") then close the output stream. On the server I receive all the headers,the correct content length but then I get a zero length line and the server hangs on readLine. What appears to happen is the client close never actually happens so the entire data is not written hence the server never gets it. I have read numerous examples and tried various changes

HttpURLConnection.getResponseCode() freezes execution/doesn't time out

孤街醉人 提交于 2019-12-10 17:24:07
问题 I'm writing an Android app that connects to a cPanel server (Apache 2.2.22) page which is password protected. When the authentication credentials are correct, I have no problem connecting. However, when the credentials are incorrect, my Android application seems to freeze in the HttpURLConnection.getResponseCode() method. The logs on the server show hundreds of requests being sent from my Android device, all returning a 401 as expected, but for some reason this is not reflected in my

java.io.IOException: Invalid Http response

与世无争的帅哥 提交于 2019-12-10 16:16:32
问题 Now before you say there are questions like this I'd like to point out I've looked over most of them without any luck. Also I'm a first timer here so be gentle. I have this annoyance right now in my current program: Basically this part of my program uses a search engine to find torrent files. public static ArrayList<String> search(String args) throws IOException { args = args.replace(":", ""); ArrayList<String> list = new ArrayList<String>(); URL url = new URL("http://pirateproxy.net/search/"

404 when accessing Tomcat with HttpUrlConnection, 200 from browser

时间秒杀一切 提交于 2019-12-10 16:04:25
问题 I am getting the weirdest Tomcat error. I have a web app running on my localhost at port 8080 using tomcat and everything appears to running great, no errors etc. However, when I try to access this web app from another app using the HttpURLConnection class, I am getting a 404 error. The weird part is, when I put the same URL in the browser it returns a 200 code and has a valid response. I have tried/checked the following from these posts : post1 and post2 Setting the User Agent and Accept

Issue streaming directions for Google Maps API v2 Android

空扰寡人 提交于 2019-12-10 15:48:24
问题 So part of my application builds a navigation directions string and then attempts to parse the JSON and draw the polyline routes on my map. I first build my string using Location variables or Locale constants. I end up with something like https://maps.googleapis.com/maps/api/directions/json?origin=Full Frame Documentary Film Festival, Durham, 27701&destination=601 W Peace St, Raleigh,27605&sensor=false&key={API_KEY} there is no new line (I added it for readability) and the {API_KEY} is my

How to stop HttpURLConnection.getInputStream()?

旧巷老猫 提交于 2019-12-10 12:49:47
问题 Below is my code: private HttpURLConnection connection; private InputStream is; public void upload() { try { URL url = new URL(URLPath); connection = (HttpURLConnection) url.openConnection(); connection.setConnectTimeout(30000); connection.setReadTimeout(30000); connection.setDoInput(true); connection.setUseCaches(false); connection.connect(); is = connection.getInputStream(); } catch (Exception e) { e.printStackTrace(); } } public void stopupload() { connection = null; is = null; } When I