Json sent from android to php defaults to index.php -
i new php. have android app sends json string myphp.php
gets redirected index.php
. normal behavior? how can go around that?
code
url url= null; httpurlconnection urlconn; url = new url ("http://192.***.*.**/myserver/myphp.php"); urlconn = (httpurlconnection)updateurl.openconnection();
this content of myphp.php.
<?php /* * change license header, choose license headers in project properties. * change template file, choose tools | templates * , open template in editor. */ //include '/index.php'; $json = file_get_contents("php://input"); $decoded = json_decode($json, true); $lat = $decoded['lat']; $lon = $decoded['lon']; sendid($pasid, $lat, $lon); function sendid($tokenid, $lat, $lon) { //request url $url = 'https://android.googleapis.com/gcm/send'; //your api key $apikey = 'key'; //payload data $data = array('lat' => $lat, 'lon' => $lon); //$registration_ids = array($tokenid); $message_id = "0000001"; $fields = array('to' => $tokenid, 'data' => $data); //http header $headers = array('authorization: key=' . $apikey, 'content-type: application/json'); //curl connection $ch = curl_init(); curl_setopt($ch, curlopt_url, $url); curl_setopt($ch, curlopt_post, true); curl_setopt($ch, curlopt_httpheader, $headers); curl_setopt($ch, curlopt_returntransfer, true); curl_setopt($ch, curlopt_ssl_verifypeer, false); curl_setopt($ch, curlopt_postfields, json_encode($fields)); curl_error($ch); //see error details $result = curl_exec($ch); curl_close($ch); echo $result; }
i used below method, namevaluepairs
, working. if php configured well, won't redirect index file. can share myphp.php
file contents?
httpclient httpclient = new defaulthttpclient(); httppost httppost = new httppost("http://192.***.*.**/myserver/myphp.php"); httppost.setentity(new urlencodedformentity(namevaluepairs)); httpresponse response = httpclient.execute(httppost); httpentity entity = response.getentity();
also try open myphp.php browser.
Comments
Post a Comment