1

I have created a http post request for connecting with Php server in android. but in server side i cant extract data from the array

this is the code for making http request

      List<NameValuePair> pairs = new ArrayList<NameValuePair>(2);
    pairs.add(new BasicNameValuePair("time",
        String.valueOf(location.getTime())));
 pairs.add(new BasicNameValuePair("latitude", new DecimalFormat("#.######").format(location.getLatitude())));
    pairs.add(new BasicNameValuePair("longitude",
            new DecimalFormat("#.######").format(location.getLongitude())));
    pairs.add(new BasicNameValuePair("speed",
        String.valueOf(location.getSpeed())));

   HttpPost post = new HttpPost(endpoint);
   post.setEntity(new UrlEncodedFormEntity(pairs));

In the eclipse i loged all the values.it is printing and i debug "pairs" it will print an array

      [locations[0][time]=1375788271891,
       locations[0][latitude]=12.966116, 
       locations[0][longitude]=77.638493,
       locations[0][speed]=0.0]

In php i tried to get this data using

              $lat=$_POST["latitude"];
              $long=$_POST["longitude"];
              $speed=$_POST["speed"];
              $time=$_POST["time"];

But iam not getting the values. whats the problem? is there aybody can help me..please reply.. Thanx in Advance :)

3
  • @Nirmal actually my problem is - the data sending from android is a array location[][]==xxxx how to extract this data from that array. thats my problem Commented Aug 6, 2013 at 11:39
  • try to follow sanders answer. you should convert your parameters to JSON. Commented Aug 6, 2013 at 11:42
  • Can you do a var_dump($_POST) of the data your submitting and show us the results. I don't think you can send that type of data without serializing it first Commented Aug 6, 2013 at 11:44

2 Answers 2

3

You could try and convert your parameters to JSON and then post them to PHP.

Sign up to request clarification or add additional context in comments.

1 Comment

how we can conver it into json? can u give one example?
0

I have done something like that, I am guessing you know how to send the data to server through php, Try this, in your php,

          $lat=$_POST['latitude'];
          $long=$_POST['longitude'];
          $speed=$_POST['speed'];
          $time=$_POST['time'];

4 Comments

i tried the same code yar..but the problem is in php it the data is getting in the format of an array. [locations[0][time]=1375788271891, locations[0][latitude]=12.966116, locations[0][longitude]=77.638493, locations[0][speed]=0.0]
then try to get your values first in a variable, then pass it.
your right.. how we get all the post data in php ? you know? after that we can extract each values .right?
Or you can extract your data in java instead, and then pass it to php, Then POST data willnot be the issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.