httpurlconnection

Default keep-alive time for a HttpConnection when using Spring Rest Template

拟墨画扇 提交于 2019-12-05 00:49:10
问题 I am trying to know how long a HttpConnection is kept alive when inactive, before a new connection is created via Spring rest Template. I looked at default Connection Time-Out and Read Time-Out parameters, but I believe these are used in the context of connection time out when the connection is not established due to some failure etc. What I am looking for is, how long a connection is kept alive if there is no activity (or) inactive, and how to configure this via Spring Rest Template (or) the

HttpURLConnection PUT to Google Cloud Storage giving error 403

谁都会走 提交于 2019-12-05 00:36:32
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; HttpURLConnection connection; try { url = new URL("http://google-testbucket.storage.googleapis.com/testdata.txt

Difference between URL.openConnection() and URLConnection.connect()?

爱⌒轻易说出口 提交于 2019-12-04 22:06:20
问题 In the code: HttpURLConnection connection = (HttpURLConnection)createMerchURL.openConnection(); connection.setRequestMethod("PUT"); connection.addRequestProperty("Name", "Value1"); connection.connect(); .. connection.disconnect(); When is the connection getting opened actually? At ..createMerchURL.openConnection(); ? or at connection.connect(); ? How can I set URL in the connection Object and use it with connection.connect() ?(as I am less comfortable with .openConnection() ) Finally, is

IllegalArgumentException at URLPermission in jre8

十年热恋 提交于 2019-12-04 22:02:00
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"); con.setRequestProperty("pragma:", "no-cache"); PrintStream ps = new PrintStream(con.getOutputStream()

Can't reset method: already connected

扶醉桌前 提交于 2019-12-04 21:18:19
I have seen this error will throw if called getInputStream before, but I have not in my code and I have checked the connected property is false, but still show this error. the code is as follow: private void testConnect() throws Exception{ HttpURLConnection con = null; OutputStream httpsend = null; String url = "https://xxxxx/goldapi/rs/checkPaymentService"; TrustManager[] trustall = new TrustManager[] { new X509TrustManager() { public java.security.cert.X509Certificate[] getAcceptedIssuers() { return new X509Certificate[0]; } public void checkClientTrusted( java.security.cert.X509Certificate[

HttpUrlConnection.getInputStream returns empty stream in Android

纵饮孤独 提交于 2019-12-04 20:30:49
问题 I make a GET request to a server using HttpUrlConnection. After connecting: I get response code: 200 I get response message: OK I get input stream, no exception thrown but: in a standalone program I get the body of the response, as expected: {"name":"my name","birthday":"01/01/1970","id":"100002215110084"} in a android activity, the stream is empty (available() == 0), and thus I can't get any text out. Any hint or trail to follow? Thanks. EDIT: here it is the code Please note: I use import

How to add parameter in httpurlconnection android

萝らか妹 提交于 2019-12-04 20:13:33
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(sourceFileUri); FileInputStream fileInputStream = new FileInputStream(sourceFile_imagepath); URL url = new

What can I do for restransmiting failed message from my web / app server (java) to FCM Server

半城伤御伤魂 提交于 2019-12-04 19:44:39
I would like to send 1000 messages and retransmit only those that failed. Is there any way? Are there any methods to identify each failed message, such as a unique message ID? As you can see, there is no identifiable message ID. Is actually possible that only one message should be resent as in this case? Should I resend only this message or all the bulk? Should I use Exponential Backoff? Then, Where can I find example source? 来源: https://stackoverflow.com/questions/51737476/what-can-i-do-for-restransmiting-failed-message-from-my-web-app-server-java

Android - HttpURLConnection parameters from Map<String, Object> via POST method

旧城冷巷雨未停 提交于 2019-12-04 19:12:09
It's Just Q&A. means just a Wiki Post. I searched a lot to make this happen. All are posting different kind of answers. I am successfully using this code now. So I'd like to share to all. Your HttpURLConnection must be inside Async Task (doInBackground). Steps: Setting up parameters in Map Function Building string in form: param=val&param2=val2 Setting up HttpUrlConnection OutputStream is used to attach values. Reading response from server using InputStream Set Parameters: Map<String,Object> params = new LinkedHashMap<>(); params.put("tag", "sda"); try { StringBuilder postData = new

Google App Engine ( Java ) : URL Fetch Response too large problems

自闭症网瘾萝莉.ら 提交于 2019-12-04 17:19:46
I'm trying to build some sort of webservice on google apps. Now the problem is, I need to get data from a website (HTML Scraping). The request looks like : URL url = new URL(p_url); con = (HttpURLConnection) url.openConnection(); InputStreamReader in = new InputStreamReader(con.getInputStream()); BufferedReader reader = new BufferedReader(in); String result = ""; String line = ""; while((line = reader.readLine()) != null) { System.out.println(line); } return result; Now App Engine gives me the follwing exception at the 3th line: com.google.appengine.api.urlfetch.ResponseTooLargeException This