Skip to content Skip to sidebar Skip to footer

Android Http Request For Cakephp Url

I have a website which was created with cakephp. I want to pass some values formed in my App to this website. When I enter the exact same URL in the browser it works. The URL is so

Solution 1:

Create List<NameValuePair> and put here yours values ("somevalue" in example). Create DefaultHttpClient() set nameValuePairs with yours value.

List<NameValuePair> nameValuePairs = newArrayList<NameValuePair>();
nameValuePairs.add(newBasicNameValuePair("tag", "TEST_TAG"));
nameValuePairs.add(newBasicNameValuePair("valueKey", "somevalue"));
HttpClienthttpclient=newDefaultHttpClient();
HttpPosthttppost=newHttpPost("www.something.com/function/add/utils.php");
httppost.setEntity(newUrlEncodedFormEntity(nameValuePairs, HTTP.UTF_8));
HttpResponseresponse= httpclient.execute(httppost);
HttpEntityentity= response.getEntity();
InputStreamis= entity.getContent();
BufferedReaderreader=newBufferedReader(newInputStreamReader(is, "iso-8859-1"), 8);
StringBuildersb=newStringBuilder();
Stringline="";
while ((line = reader.readLine()) != null) {
    sb.append(line + "n");
}
is.close();
Log.i("response", sb.toString());

On the server side in /function/add/utils.php get yours value

if (isset($_POST['tag']) && $_POST['tag'] != '') {
     $tag = $_POST['tag']; //=TEST_TAG$value = $_POST['valueKey']; //=somevalue
}
//and return some info $response = array("tag" => $tag, "success" => 0, "error" => 0);
$response["success"] = 1;
echo json_encode($response);

This $response you recive in your java code as HttpEntity entity = response.getEntity(). It may help you.

Post a Comment for "Android Http Request For Cakephp Url"