title: How to call $this->get('security.context')->getToken()->getUser() in Android
body: <p>i am new to android and i am working on one application ,In which i have to add books by posting all book details to pHp server,here i am using httpPost call to send all book details,but  in pHp server there is a line,</p>
  
  <pre><code>    $this-&gt;get('security.context')-&gt;getToken()-&gt;getUser()
  </code></pre>
  
  <p>i cannot able to call it simply by httpPost in android..so i really need help to solve this problem..so please help me how to call it in android..thanks in advance....</p>
  
  <p>this is the httppost used to send book details.. </p>
  
  <pre><code>    HttpClient httpClient = new DefaultHttpClient();
                              // replace with your url
      HttpPost httpPost = new HttpPost("www.example.com"); 
  
  
      //Post Data
      List&lt;NameValuePair&gt; nameValuePair = new ArrayList&lt;NameValuePair&gt;(3);
      nameValuePair.add(new BasicNameValuePair("book", "name"));
      nameValuePair.add(new BasicNameValuePair("price", "rate"));
      nameValuePair.add(new BasicNameValuePair("author","author"));
  
      //Encoding POST data
      try {
          httpPost.setEntity(new UrlEncodedFormEntity(nameValuePair));
      } catch (UnsupportedEncodingException e) {
          // log exception
          e.printStackTrace();
      }
  
      //making POST request.
      try {
          HttpResponse response = httpClient.execute(httpPost);
          // write response to log
          Log.d("Http Post Response:", response.toString());
      } catch (ClientProtocolException e) {
          // Log exception
          e.printStackTrace();
      } catch (IOException e) {
          // Log exception
          e.printStackTrace();
      }
  
  }
  </code></pre>
  
  <p>this is the php post function</p>
  
  <pre><code>    public function handlePOST($params, Request $request) {
      $book = new Book();
  
      if (isset($params['isbn'])) {
          $book-&gt;setIsbn($params['isbn']);
      }
  
      $book-&gt;setTitle($params['title']);
  
      if (isset($params['type'])) {
          $book-&gt;setFrequency($params['type']);
      }
  
      if (isset($params['period'])) {
          $book-&gt;setPeriod($params['period']);
      }
  
      if (isset($params['frequency'])) {
          $book-&gt;setFrequency($params['frequency']);
      }
  
      if (isset($params['type'])) {
          $book-&gt;setType($params['type']);
      }
  
      if (isset($params['author'])) {
          $book-&gt;setAuthor($params['author']);
      }
  
      if (isset($params['lang'])) {
          $book-&gt;setLang($params['lang']);
      }
  
      if (isset($params['pages'])) {
          $book-&gt;setPages($params['pages']);
      }
  
      if (isset($params['price'])) {
          $book-&gt;setPrice($params['price']);
      }
  
      if (isset($params['status'])) {
          $book-&gt;setStatus($params['status']);
      } else {
          $book-&gt;setStatus(1);
      }
  
      if (isset($params['bookCondition'])) {
          $book-&gt;setBookCondition($params['bookCondition']);
      }
  
  
      //$book-&gt;setAvailableFor($params['availableFor']);
  
      if (isset($params['description'])) {
          $book-&gt;setDescription($params['description']);
      }
  
      if (isset($params['genre'])) {
          $book-&gt;setGenre(json_encode($params['genre']));
      }
      // $repository = $this-&gt;getDoctrine()-&gt;getRepository('UserBundle:User');
   //    $user = $repository-&gt;findOneBy(
   //                   array('id' =&gt;$params['userid'])
   //          );
  
      //how to call below code    
      $user = $this-&gt;get('security.context')-&gt;getToken()-&gt;getUser();
      $user-&gt;setRewardPoints($user-&gt;getRewardPoints() + 10);
      $book-&gt;setCreatedBy($user-&gt;getId());
  
      $em = $this-&gt;getDoctrine()-&gt;getEntityManager();
      $em-&gt;persist($book);
      $em-&gt;flush();
  
     // $this-&gt;triggerBookChange($book-&gt;getTitle(), $params['type']);
  
      $response = new Response(json_encode($params));
      $response-&gt;headers-&gt;set('Content-Type', 'application/json');
      return $response;
  }
  </code></pre>