如何从Android的发布数据Yii框架服务器获取错误 [英] How to post data from android to yii framework server getting error
问题描述
我从Yii框架断绝获得价值时患问题。从警予开发商的一面,他说我你是什么给我任何输入数据,但我都准备好给从XML格式的数据。他说,我收到开关输入无效。
I am suffering problem during getting value from yii framework sever. From yii developer side , he says me you are nothing giving me any input data, but i all ready give data from xml format. He says, i am getting imput null.
YII开发人员对我说:他让输入空
YII developer Said to me: He getting null in input
$输入= $ GLOBALS ['HTTP_RAW_POST_DATA'];
$input = $GLOBALS['HTTP_RAW_POST_DATA'];
为什么输入为空,将你们这个问题背后的想法。
我的Android端:
My android side:
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;
}
}
像这样的
下面我得到的回应:
Here I am getting response like this:
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框架,它不工作。
YII Developer said, Input getting empty. I did not understand. it actually words fine non MVC Framework PHP, but in MVC framework in YII, it not working.
所以,请给我这样的招数,如何发布使用于Android的XML数据YII服务器即可。并在上面究竟错在我的code。
So please give me so tricks, How to post data using xml from android to YII server . and in Above what actually wrong in my code.
推荐答案
我不会直接访问超全局变量在Yii中
I would not access directly superglobals in yii
有
Yii::app()->request->getQuery()
或
Yii::app()->request->getPost()
如果你真的需要得到HTTP_RAW_POST_DATA
If you really need to get the HTTP_RAW_POST_DATA
<?php $postdata = file_get_contents("php://input"); ?>
http://php.net/manual/en/reserved.variables。 httprawpostdata.php
这篇关于如何从Android的发布数据Yii框架服务器获取错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!