Android :: Httpclient Multipart Form Upload
Jun 2, 2009
I'm trying to do multipart form upload using the 4.x httpclient on android. all the 4.x code samples I'm seeing use org.apache.http.entity.mime.MultipartEntity, but I'm running into a roadblock trying to find it. It's supposed to be in the httpmime project, but the download link for that project leads me back to httpcore, and the httpcore download doesn't contain that class. anyone else get multi part form upload to work?
View 2 Replies
Jul 14, 2010
As described in this answer you cannot grab a progress of a multipart/form POST upload in Android using only the Android SDK, because there is an issue with the stream buffering when using HttpURLConnection which will be fixed post Froyo (see http://code.google.com/p/android/issues/detail?id=3164#c6).
Since the Apache HttpClient 3.1 was removed from the SDK quite early and the new HttpClient, which is now part of the SDK, wasn't adopted completely (it misses multipart capabilities) you can add the missing parts (specifically apache-mime4j-0.6.jar and httpmime-4.0.1.jar) to perform a multipart/form-data upload AND grab the progress of the upload (also described in the answer mentioned above).
Now, the reason why I open a new question is, that doing as described leads to an enormous growth of the installed app size (in my case from 170kb to 732kb).
So, the question is: Is there any other way to perform a multipart/form-data upload and grab the upload progress without increasing the app size that much? Are there any other libraries one can use or is there any other alternative way, not mentioned here?
View 1 Replies
View Related
Jul 29, 2010
This is my code.
I got Http 400 error.
CODE:...................
View 2 Replies
View Related
Jun 9, 2009
HttpClient 4 doesn't have that included anymore. The upstream project didn't integrate it from the 3.x client. I had to do exactly the same today. Basically I solved it by including some additional jars: mime4j httpmime This question was already on the list and there's some better explanation: http://groups.google.com/group/android-developers/msg/1ea124b384da9dc2 -- Urs My problem is that while i know what i have to include, i can't find a sensible download link for httpmime. the page points back to httpcore for downloads, but of course it's not in there any more (i checked). i was up for compiling it, but the source link takes me to the javadoc! something is definitely screwed up.
View 14 Replies
View Related
Oct 12, 2010
As part of my Android app, I'd like to upload bitmaps to be remotely stored. I have simple HTTP GET and POST communication working perfectly, but documentation on how to do a multipart POST seems to be as rare as unicorns.
Furthermore, I'd like to transmit the image directly from memory, instead of working with a file. In the example code below, I'm getting a byte array from a file to be used later on with HttpClient and MultipartEntity.
CODE:..............
This all seems fairly clear to me, except that I can't for the life of me find out where to get this ByteArrayPartSource. I have linked to the httpclient and httpmime JAR files, but no dice. I hear that the package structure changed drastically between HttpClient 3.x and 4.x.
Is anyone using this ByteArrayPartSource in Android, and how did they import it?
After digging around in the documentation and scouring the Internet, I came up with something that fit my needs. To make a multipart request such as a form POST, the following code did the trick for me:
CODE:.....
The HTTPMultipartMode.BROWSER_COMPATIBLE bit is very important.
View 1 Replies
View Related
Jan 13, 2010
I'm building an android app which should perform a GET on my site to get two cookies and then perform a post to the same site with these cookies.
As mentioned I start of with the GET and I'm using org.apache.http.client.HttpClient to perform this operation.
CODE:..............
So far so good. Don't mind the requiredCookies line yet, it will be used in the Java.net impl since I can't get the HttpClient one to work =(.
Let's take a look at the non working HttpClient Post part.
CODE:............
What happens now is that I perform a POST with the localContext where the cookies are stored. This doesn't work. I get a HTTP/1.1 401 No session. Since I had no luck with this I tried another approach(java.net.HttpURLConnection). Remember I still use the same GET part
CODE:.............
And VIOLA a 200 is displayed and everything works like a charm.
View 2 Replies
View Related
Apr 3, 2010
My problem is that I try to upload an image and some text values to an rails server, and the text values end up as files, insted of just param values.
How the post looks on the server
CODE:..........
Part of the android code
CODE:..................
View 1 Replies
View Related
Jul 2, 2009
I got one blog which interacts with servlets... Link as follows
http://groups.google.com/group/android-developers/browse_thread/threa...
In that program 2 libraries were used..
1---> import org.apache.commons.httpclient.HttpClient; 2---> import org.apache.commons.httpclient.methods.GetMethod;
When i check these libraries in my program, its show error....how to resolve this error?
View 11 Replies
View Related
Sep 14, 2010
I wanna grab the form-element and everything inside it from a web site and then load it to my own WebView. I have looked around, but since I'm quite new to parsing overall, I really need help. I've looking at some solutions; but I don't get it.
View 1 Replies
View Related
Jan 29, 2009
I am trying to send a multipart SMS using the following code. While the SMS is being split into multiple parts and sent across, in the receiver, I am seeing some junk characters (as if i am reading a binary file). Obviously, I am not doing something correct.
CODE:....................
View 2 Replies
View Related
Jan 7, 2010
I'm trying to do something I thought would be relatively simple: Upload an image to a server with the Android SDK. I'm found a lot of example code:
http://groups.google.com/group/android-developers/browse_thread/thread/f9e17bbaf50c5fc/46145fcacd450e48
[url]
But neither work for me. The confusion I keep running into is what is really needed to make a multipart request. What is the simplest way to have a multipart upload (with an image) for Android?
View 1 Replies
View Related
Jul 13, 2009
I have a class that implements a multipart file upload. The code works on every java client I've tried it on but does not work on Android, *and* it's the only HTTP request code in my Android app that doesn't play nice with my back end service. I've looked through the posts to see if other are having similar issues but so far have only found posts like this http://groups.google.com/group/android-developers/msg/c4b0270153d194d9 , which are nearly the same as mine. T The symtoms I'm seeing are that the connection responseCode is "-1" & no entries show up in the Apache access or error logs. It seems as if the request is never making it off of the android platform. The code gets right through the connection writes in the debugger with no errors, but hangs on the connection read, times out and then returns with -1. Behavior is same for real phone and emulator. As I mentioned, this code is in use elsewhere and works fine.
Does anyone know of any gotchas one needs to look out for when posting a multipart file in Android? Anything about doing a POST or a POST w/ data on Android?
I'm including the code/class below so you can see what I'm up to.
CODE:.................
View 2 Replies
View Related
Apr 27, 2010
I'm working on a sample application that does FileUpload using Multipart post, with Andorid 1.6 SDK the application works as expected but with 2.1 there is an issue basically the application does not execute and stays stale as soon as the upload process has started.
Basically, i use "java.net.URLConnection" for establishing connectivity with the server. Is there any changes made with the core Java API's in Android SDK 2.1 that causes this issue.
View 2 Replies
View Related
Sep 11, 2010
I would like to develop an application that uploads an image and some text data about that image.
To do that, I am trying to create a HTTP Multipart Post, as follows:
code:..........
My doubt is: how can I extract those values in the server? I would like to develop a Servlet to receive and process the post requests. In this Servlet I would need to extract these values in th request. Can you help me? Do you have any sample of server to answer the android multipart requests?
View 2 Replies
View Related
May 10, 2009
In response to a request over here: http://bit.ly/E1Qqm
This is some sample code for uploading an image to the web, as part of a multipart message. It assumes that the photo is stored on the SD card as "photo.jpg". You'll need to download and add a couple of jar files to the project's built path - commons-httpclient.jar and httpcomponents-client-4.0-alpha4.
It is working on my device. However (big caveats here) - it's much slower than I would like, and much slower than other applications I've installed that upload photos. It also feels hacky - e.g. the way the background thread communicates problems with the upload to the main thread using variables. I'm sure there must be a neater way to do it.
If you figure out a way to improve the code,
code:............
View 5 Replies
View Related
Sep 7, 2010
I'm having trouble uploading pictures I've taken on my DX to facebook through the "Quick Upload" option.I got a few uploaded, so I know it works, but now everytime I try, the status bad fills up all the way to "Uploading 100%" then it stalls before giving me the error "Can't send response now.Try again later."I've tried turning Wi-Fi on or off, but on both Wi-Fi and 3G it's not working.Thoughts?
View 1 Replies
View Related
Aug 24, 2010
I haven't used the Java HttpClient before and the documentation is confusing. Say I want to send a POST to the URL "https://domain/foo/ bar". I'm accessing a server with an XML API that defines the message to send like this:
code:.........
And the response to expect like this:
code:..........
Now, I can build and parse the portion inside the serverapi tags but I'm not sure how the HttpClient handles the header. If I use the standard code like this:
code:...........
In the area shown as "not sure", should I pre-pend the entire header in front of the xml section, just as it's shown in the server API document or does the client take care of the first line, since it knows the URL?
Is there a way to see exactly what is about to be sent right before I call HttpClient.execute?
As for parsing the response, I believe I can just do this:
code:..........
Or do I need to strip anything off the response content before I start parsing the xml? I took a few stabs at this and it looks like there's some HTTP bookkeeping information at the start of the response content.
View 13 Replies
View Related
Jun 21, 2010
I'm writing a small application which needs httpclient lib, basically to manage the cookie/session automatically. The website I'm targeting needs a valid session, so, between each http call, I need to send the cookie. Httpclient does it well. This is a tv stream application and I have to fetch the channel url, the url has a token parameter and I have to be logged / authenticated / (=> have a valid cookie/sessionid) to fetch the channel url.
I got the first cookie/sessionid with the first connection to the website. The cookie is valid for a certain amount of time, there is no "expires" but I don't know if there is any server cron to cleanup the sessions. I assume I have to "ping" every x secondes to maintain the session valid.
Between each http call, the time could be from 1 sec to several minutes, it depends if the user wants to change the watched tv channel. The http call (to fetch the url) is not made by the UI Thread.
There are several possibilities to manage the httpclient : - a single httpclient static singleton instance accessed by a custom synchronized getClient() on an helper class => when / how to release the http connection ? How to handle that correctly if the user got a phone call / does not use the application for now (unvalidate during onResume, etc)? - Save the cookie (String serialized into SharedPreferences) and create every time a new httpclient instance (then set the cookie to the new instance) => overhead to get the http connection - other ?
View 5 Replies
View Related
May 26, 2010
By default HttpClient use HTTP/1.1 protocol, is there any way to change it to HTTP/1.0?
View 4 Replies
View Related
May 28, 2009
I had configure a Tomcat webserver with SSL and client autification. So I need a clienKey.p12 File to visit the site. If I import the key into Firefox, it works fine.
So I tried to develop a Client from "normal" Java. That works:
CODE:..........
Now I try to develope a Client into Android and I am getting crazy....
Here my two Android implementation:
CODE:...........
I always geht the following Exception:
CODE:................
But the key is the same that I use for the "normal" java Client and for the import into firefox. So the key is valid. But it is signed by me... I don't want to sign it by a commercial Company like verisign.
View 2 Replies
View Related
Apr 8, 2010
I'm new to implementing HTTPS connections in Android. Essentially, I'm trying to connect to a server using the org.apache.http.client.HttpClient. I believe, at some point, I'll need to access the application's keystore in order to authorize my client with a private key. But, for the moment, I'm just trying to connect and see what happens; I keep getting an HTTP/1.1 400 Bad Request error.
I can't seem to make heads or tails of this despite many examples (none of them seem to work for me). My code looks like this (the BODY constant is XmlRPC):
CODE:.......................
View 1 Replies
View Related
Jun 19, 2010
For example: Say I searched something on the Walmart homepage. Like this. How would I retrieve the information from the first product listed. Information like product name, price, details, rating, model. And how would I search in the box.
The only way it seems like to me is to replace http://www.walmart.com/search/search-ng.do?
search_constraint=0&ic=48_0&search_query=someProduct&Find.x=0&Find.y=0&Find=Find.
Then replace someProduct with the seach and call it in an HttpClient.
View 1 Replies
View Related
Aug 26, 2010
Has anyone tried to use a newer version of Apache HttpClient on Android? There's an annoying bug in the HttpClient used by Android and I was wondering if I would run into problems trying to redistribute HttpClient 4.1 with my app.
View 2 Replies
View Related
Jun 25, 2010
I am using httpclient for my android app and I have a local site which has a few https pages. Since default httpclient doesnot allow self-signed certificates I am using "EasySSLFactory" and "EasyX509TrustManager", which are mentioned in httpclient documentation.
CODE:.......
The problem is if I use this SSLFactory in my android app, I am getting correct response from my site's https pages, but I get "SSL handshake failure: I/O error during system call, Unknown error: 0" for sites such as "gmail.com", "ymail.com". If I don't use. "EasySSLSocketFactory" I get response from these sites but get exception for my site.
This page fetch code works fine as a standalone java application.
View 1 Replies
View Related
May 7, 2010
I'm connecting to a REST service using HttpClient under Android. I'd like to be able to write code where I could pull the host, port, etc. out of a properties file and not have to write fake Schemes and other things like that in order to do the development work. In other words, the live site will have a cert. The dev site will have a self-signed cert or a CA cert. Either way, I need the code to seamlessly work with both kinds of certs if possible. Can someone point me in the right direction?
View 2 Replies
View Related
Apr 21, 2009
Does anyone know how to avoid the XSL transforming that is taking place in the HTTPClient? I just want the raw xml.
View 5 Replies
View Related
Nov 16, 2010
I am having a hugely annoying issue with delays using HTTPClient and post the first time I call execute on the client the response takes 5 seconds to come back. Subsequent calls take around 100 to 200 ms. I am using the Apache client so does anyone know why this takes so long? The client setup looks like below
CODE:.........
The timing for this look like below.
CODE:......................
View 8 Replies
View Related
Nov 9, 2010
I'm trying to call a web server that is using relative URL redirects for some of the calls. This of course isn't working with DefaultHttpClient as it isn't treating it as a relative URL. I've gotten as far as implementing a RedirectHandler in an attempt to catch the redirect and add in the base call but I can't work out how to get the location of the redirect.
With the following method how do I go about finding out where I am being redirected to? I can't find any fields on either response or context that have what I need and I don't know where else to look.
public URI getLocationURI(HttpResponse response, HttpContext context)
View 1 Replies
View Related
Oct 23, 2009
Until recently, our app shared a single Apache HttpClient instance using the ThreadSafeClientConnManager across the whole application. The http client instance was held by a singleton class.
Since I dislike the singleton pattern for its numerous problems, I refactored our API accessor to be a per-thread object, but now for every thread (which mostly means per Activity/Service in our case) a new HttpClient instance is created.
It's not that I have problems with this new approach, but I've read that the Apache folks suggest to only have one instance per app for performance reasons.
Visually, what we did before was this:
HttpClient (thread safe)
|
|
/
/
Activity1...ActivityN
Now, we do this:
Activity1 ... ActivityN
| |
| |
HttpClient1 HttpClientN
How do you guys do this in your applications? If you share one single HttpClient across your app and potentially many concurrent threads, how do you handle access to it?
View 1 Replies
View Related
Mar 16, 2010
I am trying to use a certain wrapper of HttpClient, called HTTPRequestHelper with an associated responseHandler as the basic class for my wrapper to a web service which is implemented as a singleton.
HTTPRequestHelper and samples of usage are described in chapter 6 of "Unlocking Android" published by Manning.
My problem is that invoking both the helper and the handler from a thread started on the main UI thread (either from an AsyncTask or directly) works only sporadically.
Here is the basic setup.
public class APIService { private ArrayList<Something> myThing;
CODE:.................
View 2 Replies
View Related