title: Login using Curl Php (POST method)
body: <p>Hi every one,
               I have a login form which has mail id and password, on submit it should call an api which inturn generates a auth token. I have used POST method in Php curl but getting the following error.</p>
  
  <p>Apache Tomcat/6.0.36 - Error report
  .. some html styles..
  The server refused this request because the request entity is in a format not supported by the requested resource for the requested method</p>
  
  <p>and this is my ajax call..</p>
  
  <pre><code>function callapi()
  { 
  data = new Object();
  var email= document.getElementById("input01").value;
  var pwd=document.getElementById("input02").value;
  if(email != ""&amp;&amp; pwd != "")
  {
  data.Email = email;
  data.Pwd = pwd;
  
  }
  
  jQuery.ajax({ 
    url: "http://localhost/stackato/nlogin.php",
    type: "POST",
    dataType:"json",
    data:data,
    error: function (data) {
     alert('error--'+data);
    },
    success: function (data) { 
  
  if(data=="invalid")
  {
  
  }
  else
  {
  
  window.location.href="finalstackatolists1.html";
  }
  
  
  
  }
  });
  
  }
  </code></pre>
  
  <p>and this is my curl php page</p>
  
  <pre><code>&lt;?php
  header('Content-type: application/json');
  $url = $_SERVER['REQUEST_URI'];
  $scriptname = $_SERVER['SCRIPT_NAME']; 
  $queryString = $_SERVER['QUERY_STRING'];
  $mail=$_POST["Email"];
  $pwd=$_POST["Pwd"];
  $action = $_POST["action"];
  
  
  $nurl = str_replace($scriptname,"...the api...",$url);
  
  
  
  
  //open connection
  
  $ch = curl_init(); 
  $data = array("username" =&gt; $mail, "password" =&gt; $pwd);                                                                    
  $req_data = json_encode($data);  
  
  curl_setopt($ch, CURLOPT_URL, $nurl);
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $req_data);
  curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  
  
   //execute post
  
  if( ! $result = curl_exec($ch)) {
      die(curl_error($ch));
      curl_close($ch);
  }
  
  if(curl_getinfo($ch, CURLINFO_HTTP_CODE) == '500')
  {
      header("Status: 500 Server Error");
  }
  
  curl_close($ch);
  
  
  echo $result;
  
  
  ?&gt;
  </code></pre>
  
  <p>(I tried it in REST-Client and the token has been generating)</p>
  
  <p>Please help me to solve this.. thanks in advance..</p>