httpurlconnection

Java: HTTP PUT with HttpURLConnection

回眸只為那壹抹淺笑 提交于 2019-12-07 02:35:47
问题 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 =

SSLHandshakeException: Certificate Exception using HttpURLConnetion with Android 4.2.2

谁都会走 提交于 2019-12-07 02:28:54
问题 I am struggling with a strange issue, while using HttpURLConnection for webservice api call in Android. I am getting below exception ONLY with Android version 4.2.2 . It is working fine in Android 4.0.3, 4.3 and 4.4 and above. I am using below code for service api call. HttpURLConnection mConn = (HttpURLConnection)mUrl.openConnection(); mConn.addRequestProperty("Connection", "close"); mConn.setConnectTimeout(CONNECTION_TIMEOUT); mConn.setReadTimeout(SOCKET_TIMEOUT); mConn.setUseCaches(true);

Volley behind a proxy server

只谈情不闲聊 提交于 2019-12-07 02:02:46
问题 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

Sending UTF-8 string using HttpURLConnection

随声附和 提交于 2019-12-06 18:21:40
问题 till now I've used the following code snippet in order to send and recieve JSON strings: static private String sendJson(String json,String url){ HttpClient httpClient = new DefaultHttpClient(); String responseString = ""; try { HttpPost request = new HttpPost(url); StringEntity params =new StringEntity(json, "UTF-8"); request.addHeader("content-type", "application/json"); request.setEntity(params); HttpResponse response = httpClient.execute(request); HttpEntity entity = response.getEntity();

Can't reset method: already connected

风流意气都作罢 提交于 2019-12-06 14:54:18
问题 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()

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

允我心安 提交于 2019-12-06 14:17:40
问题 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>

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

試著忘記壹切 提交于 2019-12-06 13:44:57
问题 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

JAVA: How to create http url connection selecting the ip address to use

天涯浪子 提交于 2019-12-06 13:41:28
I have a pool of public ip addresses configured on my multiple NICs. In my JAVA project, which runs on a LINUX machine, I need to select a specific ip address from the pool and create an HttpURLConnecion using that ip. Further, I will cycle on the pool, using each time a different ip. At the current stage, I was not able to find a solution using the java.net library. I have rather looked at the HttpClient from Apache. At the following link, http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html , it is said that such library can support the functionality I was looking for. A

Sending binary data with HttpURLConnection

♀尐吖头ヾ 提交于 2019-12-06 13:22:00
i want to use google speech api, i've found this https://github.com/gillesdemey/google-speech-v2/ where everything is explained well, but and im trying to rewrite it into java. File filetosend = new File(path); byte[] bytearray = Files.readAllBytes(filetosend); URL url = new URL("https://www.google.com/speech-api/v2/recognize?output="+outputtype+"&lang="+lang+"&key="+key); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); //method conn.setRequestMethod("POST"); //header conn.setRequestProperty("Content-Type", "audio/x-flac; rate=44100"); now im lost... i guess i need to add

How do I submit variables from Android Activity to website url?

有些话、适合烂在心里 提交于 2019-12-06 11:47:29
问题 I have an application built that works like a form, it takes four fields and validates the information in order to make sure that no invalid characters are entered. These four fields are stored in variables: Phone Name Email Comments Now I want to submit the form data (whatever is entered into these four fields and stored to the variables) to a url (will use http://www.test.com), but I am not sure how to go about doing this. I think I am looking for something called the HttpURLConnection, but