Send parameter in HTTP POST - android

I am using this code http://stunningco.de/2010/04/25/uploading-files-to-http-server-using-post-android-sdk/ to send an image to my web server the code works fine but i want to be able to send some aditional parameters.
How can i send them , i tried constructing the url request like this http://www.mywebserver.com/postdata?param1=somevalue&param2=somevalue but the web server never reconisez them.
Thanks.

I don't know how did you program your custom server, but you passed the additional parameters the right way (via GET, not POST).
If you did it from scratch, by reading the HTTP protocol packets and interpreting them manually, then you'll have your GET parameters just after the requested URL at the first line, and will have to split the url by first using the '?' character to split the url from the parameters, then the '&' to split the different parameters into an array, and then split each parameter using the '=' character into a key and a value.
If that's not the case and used some kind of pyhon/Java/VB.NET library, please tell us which one..

Related

POST And GET Request in android studio [duplicate]

This question already has answers here:
What is the difference between POST and GET? [duplicate]
(7 answers)
Closed 4 years ago.
I am using android studio and got me wondering what's the difference of using post and get method request. I know when we use GET METHOD as a request in front end, we would see the request parameters in the url. But in android there aren't any url, so what difference does it make when using post method and get method in android ?
Well, The main difference is GET passes request parameter in URL string while POST passes request parameter in request message body which makes it more secure way of transferring data from client to server in http protocol
But if you look more into it, there are any other difference:
First
GET is used for data retrieval only. you can refine what you get from GET METHOD but it is as read only.
While POST is used for send data, But it only like a way to break the simple workings of HTML because you are neither guaranteed of anything that is happening, while it can fetch, send, or delete a data.
Second
GET request can only pass limited amount of data while POST method can pass large amount of data to server
Third
GET is mostly used for view purpose (e.g. SQL SELECT) while POST is mainly use for update purpose (e.g. SQL INSERT or UPDATE).
Fourth
the result of POST may not result in an actual page.
and Lastly
If you have a HIDDEN inputs in form then submitting a GET request reveals that HIDDEN inputs. (PHP GET and POST)

android volley form post requests are always out of order

so i am using volley to connect to a backend and for some reason they need the form request data to be in a certain order the server wont accept it. unfortunately no matter how i put my data into the hashmap when overriding getParams they always come out in the same, incorrect order causing me to be unable to make a request. is there a way for me to order it, or just create my own string and send that? thanks

Passing JSON string in the URL parameters using Spring & Robospice

I am writing a rest client application and the way the server has been set up (beyond my control) is to perform specific filters the query string has a raw json attached as follows:
http://www.someurl.com/api/user?filter=[{"field1":"value1","field2":"value2","field3":"value3"}]
Currently I am using Robospice/Spring to handle the network requests and for regular queries (i.e. no json paramters) it works pretty well. However, whenever I try and process a GET request with the above described url, I keep receiving 500 server error. I tried the same request using This android-async-library, which seems to be able to handle the parameters a little better (200 OK etc). This has lead me to believe the issue is with the way the URL is formed/parsed.
My question is can Spring handle URLs of this format? or if anyone knows the best way to handle/encode it that will be usable for spring?
Yes possibly your url should be encoded especially when you post json in parameters(because of ", :, }, ' notations)
use this for creating your url
String url = Uri.parse("http://youradres.com")
.buildUpon()
.appendQueryParameter("filter", "[{\"field1\":\"value1\",\"field2\":\"value2\",\"field3\":\"value3\"}]")
.build().toString();
It is probably not a good idea. I would pass those values like this:
http://www.someurl.com/api/user?field1=value1&field2=value2&field3=value3
And manage those values on your controller. I think it is more rest-ish. However, going straight to your question. I think the problem is you need to "encode" your URL before you send those values. And then decode it back in your server.
I can not give you code because I don't use Java but this might help you to get on the right track.

Send long string (Base64 encoded image) via HttpGet

I'm trying to send an image as a Base64 encoded string to my PHP script via HttpGet, but as I kind of expected I get a 414 URI too large from my server.
Is there a way to post large strings with HttpGet?
Any help is greatly appreciated.
URI limit depends on server settings and its not a good idea to send huge data via Get method. And no, you cant use Post on Get service.
The best would be to alter your webservice to receive Post request and then you may send as long data as you want
when the URI is too large (cause of you are using it to send an image...) all you can do is to try to make it smaller, by compressing it. Or if you have access to the server, increase the limit....
the one way or the other.... use http-post instead of http-get.
you wont have the problem that the size is limited (or if theres a limit, its way bigger then the one from http-get) and i cant believe that sending an image via http-get is usage as intended by the http

Send parameters along with file in android to server

I am using this code to send a file to server
upload an image and audio in One request in android
Now my problem is I want to send some string parameters along with request.
How can I do that?
I don't have any hands on experience with this, but from looking at your code, I would think you could do it in the code below
entity.addPart("NEW_PARAMETER", new StringBody("some_value"));
Couldn't you just add more of these, and get them in your server side code just like your accessing the other values your sending?

Categories

Resources