httpurlconnection

How to post an image to server in android

放肆的年华 提交于 2019-12-24 00:40:43
问题 How do I upload an image to the Server? Both MultiPArtEntity and MultiPartEntityBuilder classes are deprecated in API level 23. Can we do this using HTTPUrlConnection or volley? 回答1: I suggest that you use OkHttp. More details about it you can find at the following: OkHttp - An HTTP & SPDY client for Android and Java applications Please refer to my basic sample code that uploads a PNG file from drawable folder to remote web service. Hope this helps! ... mTextView = (TextView) findViewById(R

Send Multiple POST Requests Through a DataOutputStream in Java

 ̄綄美尐妖づ 提交于 2019-12-23 19:41:18
问题 I am trying to use a for loop to send multiple POST requests through a DataOutputStream and then close it. At the moment, only the first index of the " trades " array list is sent to the website. Any other indexes are ignored and I'm assuming they are not being sent. I wonder if I am properly flushing the stream? Thank you!!! Examples of trades values: "101841599", "101841801" Example of code value: 85e4c22 Snippet of my code: private ArrayList<String> trades = new ArrayList<String>();

HttpURLConnection Closing IO Streams

廉价感情. 提交于 2019-12-23 18:23:05
问题 I am new to Java and HttpURLConnection. Should I close the opened IO streams before dropping the connection. If I close the streams, should I need to drop the connection as well? Which is the proper way of implementation? try { String uri = "http://localhost:8081/RESTEASY/saju/post/text"; URL url = new URL(uri); connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); connection.setRequestProperty("Accept", "text/plain"); connection.setRequestProperty(

HTC One bug? Parts of HTTP header appearing in URLConnection InputStream

試著忘記壹切 提交于 2019-12-23 15:44:42
问题 I have some code to download an XML file that has been shipping in a paid app for a few years - never had any trouble until I recently saw this happen with an HTC One. Wondering if there is something I am missing or if this should get reported somewhere. Here is example code that forces the issue: package com.lutron.davetest; import java.io.BufferedInputStream; import java.io.InputStream; import java.net.URL; import java.net.URLConnection; import android.os.AsyncTask; import android.os.Bundle

Android HttpURLConnection PUT to Amazon AWS S3 403 error

北慕城南 提交于 2019-12-23 13:24:09
问题 Uploading a file to Amazon S3 using presigned URL which has Signature, Expiration and AccessKey, using the following code I'm able to upload the file using normal java code but same code in Android gives me 403 error. Presigned URL is generate using Amazon SDK I have read http://developer.android.com/reference/java/net/HttpURLConnection.html and http://android-developers.blogspot.com/2011/09/androids-http-clients.html but not able to figure out what header param should i use, I guess in

HttpURLConnection redirects my POST request into a GET

↘锁芯ラ 提交于 2019-12-23 12:10:46
问题 I'm sending a HttpURLConnection with setInstanceFollowRedirects(true) and POST , get a redirect response that looks like this: HTTP/1.1 302 Found Server: nginx Date: Wed, 09 Jan 2013 20:47:56 GMT Content-Type: text/html; charset=utf-8 Transfer-Encoding: chunked Connection: keep-alive Status: 302 Found Status: 301 Moved Permanently Location: http://foo.bar/... And the next request that the JVM sends is a GET request (to the correct, redirected URL). It also seems to drop one of the HTTP

“SocketException: Unexpected end of file from server” from servlet but not from standalone application

送分小仙女□ 提交于 2019-12-23 11:56:45
问题 I would like to call a servlet from my servlet. I can call the remote servlet from a standalone application but I cannot call it from my servlet (it is on Glassfish). I use exactly the same code for the call (I get the error at the last code line): URL serverAddress = new URL(endpoint); //Set up the initial connection HttpURLConnection connection = (HttpURLConnection) serverAddress.openConnection(); connection.setRequestMethod("POST"); connection.setDoOutput(true); connection.setDoInput(true)

HttpURLConnection not decompressing Gzip

天涯浪子 提交于 2019-12-23 10:41:07
问题 I'm trying to use HttpURLConnection on Gingerbread+ Android devices and am having trouble with the gzip encoding. According to the documentation "In Gingerbread, we added transparent response compression. HttpURLConnection will automatically add this header to outgoing requests, and handle the corresponding response: Accept-Encoding: gzip" The problem is that this is not actually happening. The Accept-Encoding: gzip header is not getting added at all. If I add it manually, I would then expect

Need help logging into website and retrieving information

大兔子大兔子 提交于 2019-12-23 09:41:40
问题 I have read through many similar questions, but I am still stuck with logging in to my school gradebook (https://parents.mtsd.k12.nj.us/genesis/parents) to retrieve data. My networking class is shown below: public class WebLogin { public String login(String username, String password, String url) throws IOException { URL address = new URL(url); HttpURLConnection connection = (HttpURLConnection) address.openConnection(); connection.setDoOutput(true); connection.setRequestProperty("j_username",

NameValuePair deprecated

风流意气都作罢 提交于 2019-12-23 08:57:24
问题 since Android 22 NameValuePair is deprecated. The documentation sends me to an article about openConnection, but that is what I do. So how is it replaced properly? I know I can still use it and a string has to be build, just figuring how to pass data between methods. 回答1: You can use ContentValues instead of list of NameValuePair. Creating: ContentValues values = new ContentValues(); values.put("key1", "value1"); values.put("key2", 123); Usage: for (Map.Entry<String, Object> entry : values