2

yii フレームワーク サーバーから値を取得する際に問題が発生しています。yii 開発者側から、彼は、あなたは私に入力データを与えるものは何もないと言いますが、私はすべて xml 形式からデータを与える準備ができています。彼は、私は入力がヌルになっていると言います。

YII 開発者は私に言いました: 彼は入力で null を取得しています

$input = $GLOBALS['HTTP_RAW_POST_DATA'];

なぜ入力が null なのか、この問題の背後にあるアイデアを教えてください。

私のアンドロイド側:

String url="http://test.org/site/test";     

String input = String.format("<Es_Request><Data><UserName>%s</UserName><Password>%s</Password></Data></Es_Request>",userEmail, userPassword);

String response = HttpPostRetreiver.retriver(url,input, LoginScreen.this);
Log.d("TAG",LoginScreen.java--- 'New response is------->>>' Line 246==="    + response);

およびHttpPostRetreiver.java ファイル

public class HttpPostRetreiver {

    public static String retriver(String Url, String input, Context context) {
        Log.d("TESTING", "URL->>" + Url);
        String responseString = null;
        StringEntity stringEntity;
        HttpPost postRequest = new HttpPost(Url);
        try {

            Log.e("string is", input + "\n" + Url);
            stringEntity = new StringEntity(input, "UTF-8");
            stringEntity.setContentType("application/atom+xml");

            postRequest.setEntity(stringEntity);
            //postRequest.a
            Log.v("Post", "Posted");

            HttpClient httpclient = new DefaultHttpClient();
            HttpResponse response = httpclient.execute(postRequest);
            HttpEntity getResponseEntity = response.getEntity();

            responseString = EntityUtils.toString(getResponseEntity);

        } catch (Exception e) {
            postRequest.abort();
            Log.w("HttpPostRetreiver", "Error for URL " + Url, e);
        }

        return responseString;

    }

}

ここで、次のような応答が得られます。

08-10 17:42:52.581: D/TAG(24295): LoginScreen.java--- 'New response is------->>>' Line 246===<?xml version="1.0" encoding="utf-8"?><Es_Response><Bpn_Id> </Bpn_Id><Es_Session_Id> </Es_Session_Id><UserName></UserName><Password>[]</Password></Es_Response>

YII 開発者側から:

彼は次のようにしました。

<?php 
class UserapiController extends Controller
{

    // Members
    /**
     * Key which has to be in HTTP USERNAME and PASSWORD headers 
     */

    Const APPLICATION_ID = 'ASCCPE';


    /**
     * Default response format
     * either 'json' or 'xml'
     */
    private $format = 'xml';
    /**
     * @return array action filters
     */
    public function filters()
    {
            return array();
    }

    // Actions
    public function actionList()
    {   

    //print_r($_POST);exit;



            if (isset($GLOBALS['HTTP_RAW_POST_DATA']) && !empty($GLOBALS['HTTP_RAW_POST_DATA'])) {
         $input = $GLOBALS['HTTP_RAW_POST_DATA'];
        } else {
        $input = "";
        } 

        $xmlArray = Main::xml2array($input, $get_attributes = 0);


        if (!empty($xmlArray['Es_Request']['Data']['UserName']) && !empty($xmlArray['Es_Request']['Data']['Password']))
        {
            $username = $xmlArray['Es_Request']['Data']['UserName'];
            $password = sha1($xmlArray['Es_Request']['Data']['Password']);
        }



        /* Comment below code line when integratin with android device
         * 
         */
        /*$username ="demodemo";
        $password = sha1(123456);
        $email='this@hotmail.com';*/
        // Get the respective model instance

        //print_r($username);
        //exit;
        switch($_GET['model'])
        {
            case 'list':
                $models = Individual::model()->findAll();
            case 'individual':
                $models = Individual::model()->findAll('id=2'); 
                break;
            case 'login':
                $models = Individual::model()->findByAttributes(array('username'=>$username,'password'=>$password));
                break;//print_r($models->attributes);

            case 'forgotpassword':
                $models = Individual::model()->findByAttributes(array('email'=>$email));
                break;
            default:
                // Model not implemented error
                $this->_sendResponse(501, sprintf(
                        'Error: Mode <b>list</b> is not implemented for model <b>%s</b>',
                        $_GET['model']) );
            Yii::app()->end();
        }
        // Did we get some results?
        if($_GET['model']=='login'){
            if(count($models)==0) {
            // No 
            //echo "i am here";
            $this->_sendResponse(200,
                    sprintf('No items where found for model <b>%s</b>', $_GET['model']) );
        } else {
            // Prepare response
            /* print_r($_GET['model']);
            exit; */
            $this->_checkAuth($username,$password);
            $xmldoc = '<?xml version="1.0" encoding="utf-8"?>';

            $xmldoc.='<Es_Response>';
            $xmldoc.='<Bpn_Id> </Bpn_Id>'; //The UID of the business partner.
            $xmldoc.='<Es_Session_Id> </Es_Session_Id>';
            $pcode = 1;
            $scode = 'Successful';
            $xmldoc.='<Response_Code>';
            $xmldoc.='<Pcode><![CDATA['.$pcode.']]></Pcode>';
            $xmldoc.='<Scode><![CDATA['.$scode.']]></Scode>';
            $xmldoc.='</Response_Code>';
            $xmldoc.='<Data> ';
            $xmldoc.='<UserInfo>';
            $xmldoc.='<UserId><![CDATA['.$models->id.']]></UserId>';
            $xmldoc.='<UserAccessToken><![CDATA['.$models->token.']]></UserAccessToken>';
            $xmldoc.='<Name><![CDATA['.$models->firstname.' '.$models->lastname.']]></Name>';
            $xmldoc.='<Email><![CDATA['.$models->email.']]></Email>';
            $xmldoc.='<Phone><![CDATA['.$models->phone.']]></Phone>';
            $xmldoc.='<Address><![CDATA['.$models->address->addressline.','.$models->address->city.','.$models->address->zone.','.$models->address->country->name.']]></Address>';
            $xmldoc.='<Description><![CDATA['.$models->description.']]></Description>';


            $xmldoc.='</UserInfo>';
            $xmldoc.='</Data> ';
            $xmldoc.='</Es_Response>';
            // Send the response
            //$this->_checkAuth();
            $this->_sendResponse(200, $xmldoc);


    }
        }

        if($_GET['model']==forgotpassword){

            if(empty($models)) {
                // No
                $this->_sendResponse(200,
                        sprintf('No items where found for model <b>%s</b>', $_GET['model']) );
            }   
            else{

                $xmldoc = '<?xml version="1.0" encoding="utf-8"?>';

                $xmldoc.='<Es_Response>';
                $xmldoc.='<Bpn_Id> </Bpn_Id>'; //The UID of the business partner.
                $xmldoc.='<Es_Session_Id> </Es_Session_Id>';
                $xmldoc.='<Data>';
                $xmldoc.='<UserInfo>';
                $xmldoc.='<UserId><![CDATA['.$models->id.']]></UserId>';
                $xmldoc.='<UserAccessToken><![CDATA['.$models->token.']]></UserAccessToken>';
                $xmldoc.='<Email><![CDATA['.$models->email.']]></Email>';
                $xmldoc.='</UserInfo>';
                $xmldoc.='</Data>';
                $xmldoc.='</Es_Response>';
                $this->_sendResponse(200, $xmldoc);
            }
        }
    }

  }

YII 開発者は、入力が空になると言いました。私は理解していなかった。実際には、MVC フレームワーク以外の PHP では問題ありませんが、YII の MVC フレームワークでは機能しません。

AndroidからYIIサーバーにxmlを使用してデータを投稿する方法を教えてください。上記のコードで実際に間違っていること。

4

1 に答える 1