httpurlconnection

Post request to server using HttpUrlConnection

拥有回忆 提交于 2019-12-12 18:28:05
问题 I am stuck in between. I want to implement a POST method using HttpUrlConnection to Post the email,name and password for registering a user to the server. Here is my code : public void createNewProfile(View view){ new Post().execute("http://myurl.com"); } private class Post extends AsyncTask<String, Void, String>{ @Override protected String doInBackground(String... params) { try { URL url = new URL("http://myurl.com"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn

Why HTTP/2 is not supported by Android's HttpUrlConnection?

笑着哭i 提交于 2019-12-12 17:31:24
问题 I just found out that Android's recommended http client HttpUrlConnection doesn't support HTTP/2. Is there a specific reason not to use HTTP/2 on Android? 回答1: You can use OkHttp if you want to take advantage of HTTP/2: https://github.com/square/okhttp It's superior to HttpUrlConnection anyway. If you're doing anything at all complicated, like getting complex JSON responses from a web API, I'd recommend Retrofit: https://square.github.io/retrofit/ 来源: https://stackoverflow.com/questions

How to disable buffering in Java HttpURLConnection for multi-part form post?

混江龙づ霸主 提交于 2019-12-12 15:01:44
问题 (This is for a signed applet and I have decided against HTTPClient to keep my jar very small) I am using HttpURLConnection to successfully upload a file from the user to a server using multi-part form post. The problem is that HttpURLConnection is caching the data -- before sending it. So when I am reading from the file and writing to Outputstream, it is merely buffering the data -- and therefore my progress bar, that shows the upload status , is completely wrong. Howevere please note that

Prevent unsolicited CONNECT method calls from HttpURLConnection

[亡魂溺海] 提交于 2019-12-12 10:45:21
问题 I am using HttpURLConnection along the lines of the following: String strURL = "https://example.herokuapp.com"; Bitmap bmImage = null; HttpURLConnection connection = null; InputStream in = null; showMessage(context.getString(R.string.message_preparing)); try { int timeoutMS = 15000; URL url = new URL(strURL); connection = (HttpURLConnection) url.openConnection(); connection.setDoInput(true); connection.setConnectTimeout(timeoutMS); connection.setReadTimeout(timeoutMS); connection.connect();

HttpURLConnection App Engine Java Example for POST Request does not work

别说谁变了你拦得住时间么 提交于 2019-12-12 10:08:03
问题 I am trying to do a POST request using urlfetch under an app engine application. I have followed the instructions (and code) extracted from the simple example found at the App Engine documentation (here https://developers.google.com/appengine/docs/java/urlfetch/usingjavanet), under the section "Using HttpURLConnection". import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.net.URLEncoder; import java.io.BufferedReader; import java.io

Android allow multiple file upload (Max 150 MB) to PHP Server

大兔子大兔子 提交于 2019-12-12 09:32:30
问题 I have to allow a user to upload multiple files(can be image/video/audio)in a single request from my android application to the PHP server. I am using REST web service. For this functionality, I am using the following code: /* To upload the multiple documents */ public void uploadFile() { String charset = "UTF-8"; File[] uploadFileArray = new File[mediaList.size()]; for (int i = 0; i < mediaList.size(); i++) { uploadFileArray[i] = new File(mediaList.get(i).getMediaPath()); } try {

Checking Content-Type of HTTP POST Request to Java servlet

被刻印的时光 ゝ 提交于 2019-12-12 08:58:19
问题 I've written a simple servlet that accepts HTTP POST requests and sends back a short response. Here's the code for the servlet: import java.io.BufferedInputStream; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import javax.servlet.ServletException; import javax.servlet.ServletOutputStream; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http

Cannot fetch PDF file as binary data

为君一笑 提交于 2019-12-12 08:02:09
问题 I'm trying to fetch a PDF file from: URL : https://domain_name/xyz/_id/download/ wherein it doesn't points to a direct pdf file and each unique file gets downloaded interpreting a particular <_id> field. I put this link in the address bar of the browser and Pdf file gets downloaded instantly, while when I try to fetch it by HTTPsURLConnection its Content-Type is in 'text/html' form, while it should be in 'application/pdf'. I also tried to 'setRequestProperty' to 'application/pdf' before

Java Webstart and URLConnection caching API

半城伤御伤魂 提交于 2019-12-12 07:40:07
问题 The description of the URLConnection caching API states as the last sentence: There is no default implementation of URLConnection caching in the Java 2 Standard Edition. However, Java Plugin and Java WebStart do provide one out of the box. Where can I find more information about the Webstart ResponseCache? Which Versions of Webstart on which platforms activate Caching? In which cases is it active? Only HTTP Get? Can it be configured? Is the sourcecode available? Background: Case 1 With

how to check url connection status in java

五迷三道 提交于 2019-12-12 06:56:07
问题 I am executing the get request in java using "URLConnection". I am sending the get requests to different Ip addresses in order to generate the alarm.If the url is valid it made the connection and read the data return from the url, but it doesnt return any thing if the connection is unsuccessful. I need to know is there any isconnect method in urlconnection because i need to set a flags for my program and I couldn't find any way to determine the unsuccessful connection, I am using the