httpurlconnection

How to pass an argument with POST using HttpUrlConnection

落爺英雄遲暮 提交于 2019-12-11 11:07:20
问题 EDIT: I figure out that wrapping the OutputStreamWriter in a BufferedWriter was causing the problem, so got rid of the wrapper and my POST goes through. Still wondering why the BufferedWriter was the cause. I apologize in advance, as I am just beginning to teach myself all about databases, communication between an app and a server/database, and php. Other similar questions asked have not provided an answer. I am having some trouble discerning what I'm missing when it comes to making a simple

Why does HttpURLConnection not send the HTTP request

。_饼干妹妹 提交于 2019-12-11 10:09:40
问题 I would like to open an URL and submit the following parameters to it, but it only seems to work if I add the BufferedReader to my code. Why is that? Send.php is a script what will add an username with a time to my database. This following code does not work (it does not submit any data to my database): final String base = "http://awebsite.com//send.php?"; final String params = String.format("username=%s&time=%s", username, time); final URL url = new URL(base + params); final

How to set HTTP request MOVE using HttpURLConnection?

為{幸葍}努か 提交于 2019-12-11 09:59:39
问题 How to set HTTP request method MOVE using HttpURLConnection ? Using HttpURLConnection or libraries that rely on that class, the code is throwing an exception Caused by: java.net.ProtocolException: Invalid HTTP method: MOVE . So I guess the MOVE method is not supported by the Java platform. Is there a patch or workaround for this issue / limitation? The workaround could be another java library for creating HTTP requests. EDIT: Note that the MOVE verb is supported WebDav HTTP extension. There

EOFException and FileNotFoundException in HttpURLConnection getInputStream()

我的梦境 提交于 2019-12-11 08:57:17
问题 When trying to connect to http://ws.audioscrobbler.com/2.0/ with post data using HttpURLConnection , I get (randomly) EOFException or FileNotFoundException: http://ws.audioscrobbler.com/2.0/ on my Nexus 4 running Android 4.2.2. Anybody can help? EDIT I upgraded to 4.3: same issue. public InputStream getData(String url_str, List<NameValuePair> postData) { Map<String, Object> response = new HashMap<String, Object>(); InputStream is = null; HttpURLConnection conn = null; try { URL url = new URL

HttpsUrlConnection EOFException

空扰寡人 提交于 2019-12-11 06:52:13
问题 I'm using the following code for post requests public String executeHttpPost(String uri, String data) { HttpURLConnection conn = null; URL url = null; String s = null; try { url = new URL(uri); conn = (HttpURLConnection) url.openConnection(); if (conn instanceof HttpsURLConnection) { Log.d("HTTPS", "HttpsUrl"); } conn.setDoOutput(true); conn.setDoInput(true); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); OutputStreamWriter wr =

Connection closed, EOF detected

纵然是瞬间 提交于 2019-12-11 05:33:41
问题 I want to post some json data from ADFS SSO enabled weblogic server to an https url(jetty server) but I am getting the below exception java.io.IOException: Connection closed, EOF detected at weblogic.socket.JSSEFilterImpl.handleUnwrapResults(JSSEFilterImpl.java:637) at weblogic.socket.JSSEFilterImpl.unwrapAndHandleResults(JSSEFilterImpl.java:515) at weblogic.socket.JSSEFilterImpl.doHandshake(JSSEFilterImpl.java:96) at weblogic.socket.JSSEFilterImpl.doHandshake(JSSEFilterImpl.java:75) at

Android HttpUrlConnection HttpPost receive a SocketException: no route to host

偶尔善良 提交于 2019-12-11 04:54:09
问题 Hey I try to send a HttpPost to an special Device in a local network over wifi. If I try the same code on a simple Java application it will work, but If I try the same code on android I am not able to send the HttpPost. String uri = "http://192.168.3.201:8080/remote/json-rpc/getPeripherals"; Log.i("uri", uri); String requestBody = "{\"jsonrpc\":\"2.0\",\"method\":" + "\"configclient_homedevices/getPeripherals\",\"id\":" + "\"1349942076918\",\"params\":[]}"; Log.i("uri", uri); String

Can I do an http GET and include a body using HttpURLConnection?

随声附和 提交于 2019-12-11 03:56:43
问题 I need to perform an http GET for a REST service and include a body in the GET . Unfortunately, setting #setDoOutput( true ) on the connection forces a POST . Is there anyway to send a GET with a body? Edit: The body I'm trying to send is JSON. 回答1: It is not possible to send content for an HTTP GET using HttpURLConnection . By setting setDoOutput(true) on an HttpURLConnection the verb is forced to be POST. The documentation for the REST API I was using described a JSON body for the endpoint

Execute terminal command in java with httpurlconnection and get response in json format

独自空忆成欢 提交于 2019-12-11 03:46:36
问题 I have a localhost server running on port 4000 which listens to requests sent to it and executes commands and returns output to client in a json format. I'm trying to send a request from tomcat's port 8080 to it and i need it to execute a command and send output back in json format. I was able to do it through php using curl and the command executed but I need the solution in java so I made the following code: public String sendData() throws IOException { // curl_init and url URL url = new

HttpUrlConnection is freezing my AsyncTask

浪尽此生 提交于 2019-12-11 03:06:35
问题 In the "doInBackground" function of a AsyncTask, I got the following piece of code : try { URL url = new URL(myUrl); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setReadTimeout(10000); conn.setConnectTimeout(15000); conn.setRequestMethod("POST"); conn.setDoInput(true); Authenticator.setDefault(new Authenticator(){ protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication ("myUsername", "myPassword".toCharArray()); } }); conn