android-beginners  

[android-beginners] Re: possible to send an xml file via HttpClient?

KC Dev Android 06
Thu, 18 Mar 2010 10:12:43 -0700

Hi, i have managed to figure out how to send an xml file using
httpPost.

my next question is how do i do the reverse i.e download a file but
this time using HttpGet.

So far am i on the right track in doing this?

httpclient = new DefaultHttpClient();

                        // Prepare a request object
                        get = new HttpGet(url);

                        // Execute the request
                        HttpResponse response;

                        try {
                                response = httpclient.execute(get);

                                Log.d(TAG, "Response code = " +
response.getStatusLine().toString());

                                HttpEntity entity = response.getEntity();

                                InputStream is = entity.getContent();

                                FileOutputStream fOut = 
context.openFileOutput(fileName,
context.MODE_WORLD_READABLE);


As you can see, i have stored the contents of the entity in a
inputstream and i plan to read it byte by byte and transfer the bytes
into the file output stream object i created just above. is this the
way to do it?

Is their an easier way of simply downloading the whole file and just
specify the destination?


On Mar 17, 3:24 pm, KC Dev Android 06
<kc.dev.android...@googlemail.com> wrote:
> damm i just reported one of your posts as spam  by accident. mods
> ignore that request!
>
> On Mar 17, 3:22 pm, KC Dev Android 06
>
> <kc.dev.android...@googlemail.com> wrote:
> > i dont know specificaly from the server guys but they said most likely
> > all i need from them is a http url. They have not indicated how they
> > will export the xml stuff but tbh why should i know such things? my
> > task is to simply send them data in a specific format and that format
> > is a xml file customized xml tags that will later be designed.
>
> > All im expecting from them is maybe some call back saying that the
> > data i sent to them is fine. thats all i am expecting and i therefore
> > dont see the need to know exactly what they will do with that xml
> > data.
>
> > i should only be concerned on What data and what format they want from
> > the android device.
>
> > I will check out the above links and see how far that goes for me. i
> > just wanted to know really if its possible to send an xml file via
> > http. If not then i may need to do it via socket connection.
>
> > On Mar 17, 3:03 pm, Chris Ross <cross+goo...@distal.com> wrote:
>
> > >   But, do you know exactly what sort of HTTP operation is expected by the 
> > > server, and how it expects the "xml file" to be encoded and transmitted?  
> > > If you do not know these answers, very precisely, you won't know how to 
> > > code you client.
>
> > >   As for HTTP and your second question, 
> > > seehttp://www.w3.org/Protocols/rfc2616/rfc2616.htmlandaquick google 
> > > findshttp://www.jmarshall.com/easy/http/whichmightbe at least as valuable.
>
> > >                - Chris
>
> > > On Mar 17, 2010, at 10:50 AM, KC Dev Android 06 wrote:
>
> > > > The server basically expects the contacts stored on a android device
> > > > in an xml file.
>
> > > > So in a HTTP get operation i can send any parameters i want be in a
> > > > xml file, string, int etc?
>
> > > > On Mar 17, 2:44 pm, Chris Ross <cross+goo...@distal.com> wrote:
> > > >>   You can send parameters encoded in the url of an HTTP GET operation, 
> > > >> but I wouldn't suggest using anything long.  I would suggest using an 
> > > >> HTTP POST operation, or if you actually want to treat it as a file, 
> > > >> rather than a "blob of XML data", an HTTP PUT.  Most any web server 
> > > >> software will know how to handle an HTTP POST, for sure.
>
> > > >>   The question is, what does the server expect?  This is much more an 
> > > >> HTTP question than an android question.
>
> > > >>                           - Chris
>
> > > >> On Mar 17, 2010, at 10:38 AM, KC Dev Android 06 wrote:
>
> > > >>> What im trying to do is simply send a xml file that i have created
> > > >>> into a http server. The way i understand http is that the request and
> > > >>> any kind of data ie a name value pair such as a username can be added
> > > >>> and included in the actual url string.
>
> > > >>> my question is, how do you go about constructing a url connection with
> > > >>> an xml file added to it?
>
> > > >>> On Mar 17, 2:23 pm, Chris Ross <cross+goo...@distal.com> wrote:
> > > >>>>   You probably want to look at HttpPost or HttpPut, which implement 
> > > >>>> HttpRequest, which is an available parameter to the execute() method 
> > > >>>> in the HttpClient interface.
>
> > > >>>>   Not 100% sure what you're trying to do, but that's the path of 
> > > >>>> investigation I'd suggest.
>
> > > >>>>                        - Chris
>
> > > >>>> On Mar 17, 2010, at 5:14 AM, KC Dev Android 06 wrote:
>
> > > >>>>> Any suggestions?
>
> > > >>>>> On Mar 16, 4:45 pm, KC Dev Android 06
> > > >>>>> <kc.dev.android...@googlemail.com> wrote:
> > > >>>>>> Hi, as the title says, is it possible to do so? in the examples 
> > > >>>>>> found
> > > >>>>>> herehttp://svn.apache.org/repos/asf/httpcomponents/httpclient/branches/4....
>
> > > >>>>>> It seems that HttpClient only accepts a String as its parameter? 
> > > >>>>>> how
> > > >>>>>> do i go about sending/uploading a xml file using http?
>
> > > >>>>>> thanks in advance.
>
> > > >>>>> --
> > > >>>>> You received this message because you are subscribed to the Google
> > > >>>>> Groups "Android Beginners" group.
>
> > > >>>>> NEW! Try asking and tagging your question on Stack Overflow at
> > > >>>>>http://stackoverflow.com/questions/tagged/android
>
> > > >>>>> To unsubscribe from this group, send email to
> > > >>>>> android-beginners+unsubscr...@googlegroups.com
> > > >>>>> For more options, visit this group at
> > > >>>>>http://groups.google.com/group/android-beginners?hl=en
>
> > > >>> --
> > > >>> You received this message because you are subscribed to the Google
> > > >>> Groups "Android Beginners" group.
>
> > > >>> NEW! Try asking and tagging your question on Stack Overflow at
> > > >>>http://stackoverflow.com/questions/tagged/android
>
> > > >>> To unsubscribe from this group, send email to
> > > >>> android-beginners+unsubscr...@googlegroups.com
> > > >>> For more options, visit this group at
> > > >>>http://groups.google.com/group/android-beginners?hl=en
>
> > > > --
> > > > You received this message because you are subscribed to the Google
> > > > Groups "Android Beginners" group.
>
> > > > NEW! Try asking and tagging your question on Stack Overflow at
> > > >http://stackoverflow.com/questions/tagged/android
>
> > > > To unsubscribe from this group, send email to
> > > > android-beginners+unsubscr...@googlegroups.com
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/android-beginners?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.

NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android

To unsubscribe from this group, send email to
android-beginners+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en