iam calling a webservice(php http get request)
http://website.com/admin/employee_login.php?fun_name=abc&company_code=1&employee_ss=123>ime=02:22 PM&x_id=350&v_id=9&task={"Walking":"1","Transfers":"1","OstomyCare":"1"}
but when am encoding this url am getting something different with %20 something like that, and it's not updating the tasks in the server database. Is there any method where i can pass parameters as a json array without encoding like same above ?
thank you
Before sending the url and parameters are url encoded. For instance spaces become %20. On the receiving side php should url decode the parameters. There is a php function which does that for you. After that you have the original parameters back.
use:
String value = "my url value"; // put here your url
URLEncoder.encode(value,"UTF-8")
Related
How can I send special character parameter in URLencoded form without change using volley library
I have to send
qty$1:23
qty$2:666
this data in URLencoded form using volley library but due to Volley Request class it is doing UTF encoding foe key value pairs.How can I avoid to change the parameter names.
Using Volley now parameters names are changed like qty%241:23 which is not acceptable by server.Please help me
Try encoding first:
String encoded = URLEncoder.encode(stringToEncode, "UTF-8"); and send the encoded string.
According to the documentation of this method:
This method uses the supplied encoding scheme to obtain the bytes for unsafe characters.
I have a URL which return a file.gz , i need to get the json data from this URL .. how can i do that?
I need the answer of the two steps i should follow
1- get the file from url
2- get the json data from this file
I am getting data from server by building a get request (HttpRequest). The data is not in Json format (when I open the link in a web browser, it says "This XML file does not appear to have any style information associated with it. The document tree is shown below.")
Since it is the case, when I call this line:
HttpRequest request = buildGetRequest("TreeLocation");
final LocationListResponse response = request.execute().parseAs(getResultType());
The app stops there, and I think it is because it does not regconize the resultType.
So, now I want to declare the content type as Json. Anyone knows how to declare the content type in Google http client library?
just convert your xml response into json using json library..and then you will get json response
use this link Convert XML to JSON object in Android
Edit 1:
you can add this and try
httpPost.setHeader("Content-type", "application/json");
for json respomse
I want to pass an array parameter in http request.I don't know if it can work.
And If i can do it,How to do?
Thanks.
alternative simple version, use String with unique dividers(or delimiters, whatever) in java(android),pass it and explode the string in php to array.
ex:
String toBePassed = "VAR1||VAR2||VAR3||VAR4";
and in php you can explode it like this
$var = $_GET('toBePassed'); // "VAR1||VAR2||VAR3||VAR4"
$varpiece = explode("||", $var);
echo $varpiece[0]; // VAR1
echo $varpiece[1]; // VAR2
echo $varpiece[2]; // VAR3
echo $varpiece[3]; // VAR4
you might have written your question a bit clear alright
you can use json or xml for this
check out these links they may help you
http://developer.appcelerator.com/question/136900/httpclient-post-and-json-including-array
Passing Array of objects as url parameters in request
Sending a serialized object from Android to a servlet using HTTP client
I am sending json object to server, My url having json object.Json object having special characters,how to encoding special characters in android, please help me.Thanks in advance.
Use UrlEncode.encode(yourstring, "UTF-8");
If I understood you, you want to send a json object using the url itself (that is, as a parameter). If security doesn't matter you (it will be visible), you could just encode using [Base64][1].
You should probably play with your json object to convert it to a byte[], called jsonbytes, for instance, then use Base64.encodeToString(jsonbytes, Base64.URL_SAFE) and sending this as a parameter.
Your server then should convert this Base64 encoded string into a json object, which tends to be straightforward if you're using PHP:
$jsonString = base64_decode($_GET['json']);
$json = json_decode($jsonString, TRUE);
This will give you an associative array in PHP. If you just want the json string, skip the last step.