Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用CURL进行callrest_Php_.htaccess_Rest_Curl - Fatal编程技术网

Php 如何使用CURL进行callrest

Php 如何使用CURL进行callrest,php,.htaccess,rest,curl,Php,.htaccess,Rest,Curl,我第一次在curl中使用restapi。我创建了一个api.php,并使用curl和with post方法调用该文件。在第68行,我收到一个错误请求变量,发出通知,但没有通过方法post获得其值“登录”。这是我的主意 在api.php页面上的curl请求之后,rquest var值将被登录,我们将在rquest值的帮助下调用login函数 Htaccess是: <IfModule mod_rewrite.c> RewriteEngine On RewriteCond

我第一次在curl中使用restapi。我创建了一个api.php,并使用curl和with post方法调用该文件。在第68行,我收到一个错误请求变量,发出通知,但没有通过方法post获得其值“登录”。这是我的主意

在api.php页面上的curl请求之后,rquest var值将被登录,我们将在rquest值的帮助下调用login函数

Htaccess是:

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-s
    RewriteRule ^(.*)$ api.php?rquest=$1 [QSA,NC,L]

    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^(.*)$ api.php [QSA,NC,L]

    RewriteCond %{REQUEST_FILENAME} -s
    RewriteRule ^(.*)$ api.php [QSA,NC,L]   
</IfModule>

源链接是

通知的可能重复是因为您试图访问$\u请求变量中未定义的索引。在访问变量之前,您应该首先通过isset或empty检查它是否存在,或者使用unrecommed@suppressor。
class API extends REST {
        public $data = "";
        const DB_SERVER = "localhost";
        const DB_USER = "root";
        const DB_PASSWORD = "";
        const DB = "test";

        private $db = NULL;

        public function __construct(){
            parent::__construct();              // Init parent contructor
            $this->dbConnect();                 // Initiate Database connection
        }

        /*
         *  Database connection 
        */
        private function dbConnect(){
            $this->db = mysql_connect(self::DB_SERVER,self::DB_USER,self::DB_PASSWORD);
            if($this->db)
                mysql_select_db(self::DB,$this->db);
        }

        /*
         * Public method for access api.
         * This method dynmically call the method based on the query string
         *
         */
        public function processApi(){

            $func = strtolower(trim(str_replace("/","",$_REQUEST['rquest']))); // **line no: 68**
            if((int)method_exists($this,$func) > 0)
                $this->$func();
            else
                $this->response('',404);                // If the method not exist with in this class, response would be "Page not found".
        }

        /* 
         *  Simple login API
         *  Login must be POST method
         *  email : <USER EMAIL>
         *  pwd : <USER PASSWORD>
         */

            private function login(){
        // Cross validation if the request method is POST else it will return "Not Acceptable" status

        if($this->get_request_method() != "POST"){
             $this->response('',406);
        }

        $email = $this->_request['email'];
        $password = $this->_request['pwd'];

        // Input validations
        if(!empty($email) and !empty($password)){
            if(filter_var($email, FILTER_VALIDATE_EMAIL)){
                $sql = mysql_query("SELECT user_id, user_fullname, user_email FROM users WHERE user_email = '$email' AND user_password = '".$password."' LIMIT 1", $this->db);
                if(mysql_num_rows($sql) > 0){
                    $result = mysql_fetch_array($sql,MYSQL_ASSOC);

                    // If success everythig is good send header as "OK" and user details
                    $this->response($this->json($result), 200);
                }
                $this->response('', 204);   // If no records "No Content" status
            }
        }

        // If invalid inputs "Bad Request" status message and reason
        $error = array('status' => "Failed", "msg" => "Invalid Email address or Password");
        $this->response($this->json($error), 400);
    }

    }

    // Initiiate Library

    $api = new API;
    $api->processApi();
<?php
$url = 'http://localhost/test/login/';
        $curl = curl_init();
        $curl_post_data = array(
            "pwd" => 'raj123',
            "emailaddress" => 'rajk@gmail.com',
            );
        curl_setopt($curl, CURLOPT_URL,$url);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST'); // 
        curl_setopt($curl, CURLOPT_POST, true)
        curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);
        $curl_response = curl_exec($curl);
        curl_close($curl);
        echo $curl_response;
        //$xml = new SimpleXMLElement($curl_response);

    // code adapted from Tony Spencer

?>
<b>Notice</b>:  Undefined index: rquest in <b>C:\xampp\htdocs\test\api.php</b> on line <b>68</b><br />
 $func = strtolower(trim(str_replace("/","",$_REQUEST['rquest'])));