我想问一下你是否有人遇到过这种情况,其中服务器返回一个html页面的响应。
02-06 20:41:45.835 31281-31281/com.pupt.rois E/Internet Status:﹕ Has Internet
02-06 20:41:46.135 31281-31323/com.pupt.rois I/System.out﹕ propertyValue:true
02-06 20:41:46.136 31281-31323/com.pupt.rois I/System.out﹕ [socket][20] connection /199.83.132.226:80;LocalPort=36360(0)
02-06 20:41:46.137 31281-31323/com.pupt.rois I/System.out﹕ [CDS]connect[/199.83.132.226:80] tm:90
02-06 20:41:46.385 31281-31323/com.pupt.rois I/System.out﹕ [socket][/192.168.1.10:36360] connected
02-06 20:41:46.385 31281-31323/com.pupt.rois I/System.out﹕ [CDS]rx timeout:0
02-06 20:41:46.387 31281-31323/com.pupt.rois I/System.out﹕ [CDS]SO_SND_TIMEOUT:0
02-06 20:41:46.391 31281-31323/com.pupt.rois I/System.out﹕ >doSendRequest
02-06 20:41:46.393 31281-31323/com.pupt.rois I/System.out﹕ <doSendRequest
02-06 20:41:46.441 31281-31281/com.pupt.rois I/SurfaceTextureClient﹕ [STC::queueBuffer] (this:0x5cc75fb8) fps:22.65, dur:1015.51, max:106.31, min:13.32
02-06 20:41:46.718 31281-31323/com.pupt.rois I/System.out﹕ [CDS]close[36360]
02-06 20:41:46.718 31281-31323/com.pupt.rois I/System.out﹕ close [socket][/0.0.0.0:36360]
02-06 20:41:46.719 31281-31323/com.pupt.rois I/System.out﹕ close [socket][/0.0.0.0:36360]
02-06 20:41:46.720 31281-31323/com.pupt.rois E/response﹕ <html>
<head>
<META NAME="robots" CONTENT="noindex,nofollow">
<script>
(function(){function getSessionCookies(){cookieArray=new Array();var cName=/^\s?incap_ses_/;var c=document.cookie.split(";");for(var i=0;i<c.length;i++){key=c[i].substr(0,c[i].indexOf("="));value=c[i].substr(c[i].indexOf("=")+1,c[i].length);if(cName.test(key)){cookieArray[cookieArray.length]=value}}return cookieArray}function setIncapCookie(vArray){try{cookies=getSessionCookies();digests=new Array(cookies.length);for(var i=0;i<cookies.length;i++){digests[i]=simpleDigest((vArray)+cookies[i])}res=vArray+",digest="+(digests.join())}catch(e){res=vArray+",digest="+(encodeURIComponent(e.toString()))}createCookie("___utmvc",res,20)}function simpleDigest(mystr){var res=0;for(var i=0;i<mystr.length;i++){res+=mystr.charCodeAt(i)}return res}function createCookie(name,value,seconds){if(seconds){var date=new Date();date.setTime(date.getTime()+(seconds*1000));var expires="; expires="+date.toGMTString()}else{var expires=""}document.cookie=name+"="+value+expires+"; path=/"}function test(o){var res="";var vArray=new Array();for(test in o){switch(o[test]){case"exists":try{vArray[vArray.length]=encodeURIComponent(test+"="+typeof(eval(test)))}catch(e){vArray[vArray.length]=encodeURIComponent(test+"="+e)}break;case"value":try{vArray[vArray.length]=encodeURIComponent(test+"="+eval(test).toString())}catch(e){vArray[vArray.length]=encodeURIComponent(test+"="+e)}break;case"plugins":try{p=navigator.plugins;pres="";for(a in p){pres+=(p[a]["description"]+" ").substring(0,20)}vArray[vArray.length]=encodeURIComponent("plugins="+pres)}catch(e){vArray[vArray.length]=encodeURIComponent("plugins="+e)}break;case"plugin":try{a=navigator.plugins;for(i in a){f=a[i]["filename"].split(".");if(f.length==2){vArray[vArray.length]=encodeURIComponent("plugin="+f[1]);break}}}catch(e){vArray[vArray.length]=encodeURIComponent("plugin="+e)}break}}vArray=vArray.join();return vArray}var o={navigator:"exists","navigator.vendor":"value",opera:"exists",ActiveXObject:"exists","navigator.appName":"value",platform:"plugin",webkitURL:"exists","navigator.plugins.length==0":"value",_phantom: "exists"};try{setIncapCookie(test(o));document.createElement("img").src="/_Incapsula_Resource?SWKMTFSR=1&e="+Math.random()}catch(e){img=document.createElement("img");img.src="/_Incapsula_Resource?SWKMTFSR=1&e="+e}})();
</script>
<script>
(function() {
var z="";var b="7472797B766172207868723B76617220743D6E6577204461746528292E67657454696D6528293B766172207374617475733D227374617274223B7661722074696D696E673D6E65772041727261792833293B77696E646F772E6F6E756E6C6F61643D66756E6374696F6E28297B74696D696E675B325D3D22723A222B286E6577204461746528292E67657454696D6528292D74293B646F63756D656E742E637265617465456C656D656E742822696D6722292E7372633D222F5F496E63617073756C615F5265736F757263653F4553324C555243543D363726743D373826643D222B656E636F6465555249436F6D706F6E656E74287374617475732B222028222B74696D696E672E6A6F696E28292B222922297D3B69662877696E646F772E584D4C4874747052657175657374297B7868723D6E657720584D4C48747470526571756573747D656C73657B7868723D6E657720416374697665584F626A65637428224D6963726F736F66742E584D4C4854545022297D7868722E6F6E726561647973746174656368616E67653D66756E6374696F6E28297B737769746368287868722E72656164795374617465297B6361736520303A7374617475733D6E6577204461746528292E67657454696D6528292D742B223A2072657175657374206E6F7420696E697469616C697A656420223B627265616B3B6361736520313A7374617475733D6E6577204461746528292E67657454696D6528292D742B223A2073657276657220636F6E6E656374696F6E2065737461626C6973686564223B627265616B3B6361736520323A7374617475733D6E6577204461746528292E67657454696D6528292D742B223A2072657175657374207265636569766564223B627265616B3B6361736520333A7374617475733D6E6577204461746528292E67657454696D6528292D742B223A2070726F63657373696E672072657175657374223B627265616B3B6361736520343A7374617475733D22636F6D706C657465223B74696D696E675B315D3D22633A222B286E6577204461746528292E67657454696D6528292D74293B6966287868722E7374617475733D3D323030297B706172656E742E6C6F636174696F6E2E72656C6F616428297D627265616B7D7D3B
02-06 20:41:46.721 31281-31323/com.pupt.rois E/TAAAAG﹕ org.json.JSONException: Value <html> of type java.lang.String cannot be converted to JSONArray
这是我获取值的代码
public class validate extends AsyncTask<String, Integer, String>{
JSONArray jArray;
String result, phpResponse;
boolean error;
@Override
protected String doInBackground(String... arg0) {
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(getString(R.string.url)+"/PUP_ROIS/mobile/loginlogout.php");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("login", "true"));
nameValuePairs.add(new BasicNameValuePair("type", type));
nameValuePairs.add(new BasicNameValuePair("username", username));
nameValuePairs.add(new BasicNameValuePair("password", password));
nameValuePairs.add(new BasicNameValuePair("regid", dbObj.getRegistrationID()));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line;
while((line=reader.readLine())!=null)
sb.append(line+"\n");
result=sb.toString();
Log.e("response", result);
error=true;
jArray = new JSONArray(result);
error=false;
return null;
}catch(Exception e){
error=true;
Log.e("TAAAAG", e.toString());
}
return null;
}
@Override
protected void onPostExecute(String result){
try{
if(!error){
JSONObject json_data = jArray.getJSONObject(0);
//STUDENT
if(type.equals("1")){
String type = json_data.getString("type");
String username = json_data.getString("id");
String name = json_data.getString("name");
String birthday = json_data.getString("birthday");
String gender = json_data.getString("gender");
String email = json_data.getString("email");
String yrbatch = json_data.getString("yrbatch");
String course = json_data.getString("course");
dbObj.insertToUserTable("1", type, username, name, birthday, gender, email, yrbatch, course);
}
//ALUMNI
else if (type.equals("2"))
{
String type = json_data.getString("type");
String username = json_data.getString("id");
String name = json_data.getString("name");
String birthday = json_data.getString("birthday");
String gender = json_data.getString("gender");
String email = json_data.getString("Email");
String yrbatch = json_data.getString("yrbatch");
String course = json_data.getString("course");
dbObj.insertToUserTable("2", type, username, name, birthday, gender, email, yrbatch, course);
}
//ADMIN
else{
String id = json_data.getString("id");
String type = json_data.getString("type");
String name = json_data.getString("name");
String username = json_data.getString("username");
dbObj.insertToUserTable(id, type, username, name, "", "", "", "", "");
}
checkIfLoggedin();
}
else{
showMessage("Invalid Username or Password");
enable(true);
}
}catch(Exception e){
Log.e("TAG", e.toString());
}
}
}
这是我服务器的代码,我使用PHP
<?php
// ---------------------------[DEFAULTS]-------------------------------
include 'connections/config.php';
include 'send_message.php';
date_default_timezone_set('Asia/Manila');
mysqli_query(connect(), 'SET CHARACTER SET utf8');
// ---------------------------[/DEFAULTS]-------------------------------
$type=$_POST['type'];
$login=$_POST['login'];
$username=$_POST['username'];
$password=sha1($_POST['password']);
$regid=$_POST['regid'];
// TYPE 1: STUDENT
// TYPE 2: ALIMNI
// TYPE 3: OFFICE
if($login=="true"){
if($type==1){
$sql = mysqli_query(connect(), "SELECT '".$type."' as type, stud_id as id,
CONCAT(last_name, ', ', first_name, ' ', middle_name) as name,
birthdate as birthday, gender, email, year as yrbatch, course
FROM tbl_students
WHERE stud_id='".$username."'
AND password='".$password."'");
}
else if($type==2){
$sql = mysqli_query(connect(), "SELECT '".$type."' as type, alumniID as id,
CONCAT(lastName, ', ', firstName, ' ', middleName) as name,
CONCAT(birthYear, '-', birthMonth, '-', birthDay) as birthday,
gender, Email, batch as yrbatch, course
FROM alumni_tblalumni
WHERE alumniID='".$username."'
AND `Password`='".$password."'
");
}
else if($type==3){
$sql = mysqli_query(connect(), "SELECT '".$type."' as type, office_id as id,
faculty_incharge as name,
faculty_username as username
FROM tbl_office
WHERE faculty_username='".$username."'
AND faculty_password='".$password."'");
}
$output=null;
//if(mysql_num_rows($sql) > 0)
if(mysqli_num_rows($sql) > 0){
$sql1 = "UPDATE tbl_android SET user='".$username."', type='".$type."', lastlog=NOW() WHERE regid='".$regid."'";
$result1 = mysqli_query(connect(), $sql1);
if($type==1){
$sql2 = mysqli_query(connect(), "SELECT CONCAT(last_name, ', ', first_name, ' ', middle_name) as name
FROM tbl_students
WHERE stud_id='".$username."'
AND password='".$password."'");
$row=mysqli_fetch_array($sql2,MYSQLI_ASSOC);
$names = $row["name"];
}
else if($type==2){
$sql2 = mysqli_query(connect(), "SELECT CONCAT(lastName, ', ', firstName, ' ', middleName) as name
FROM alumni_tblalumni
WHERE studNum='".$username."'
AND Password='".$password."'");
$row=mysqli_fetch_array($sql2,MYSQLI_ASSOC);
$names = $row["name"];
}
else if($type==3){
$sql2 = mysqli_query(connect(), "SELECT
faculty_incharge as name
FROM tbl_office
WHERE faculty_username='".$username."'
AND faculty_password='".$password."'");
$row=mysqli_fetch_array($sql2,MYSQLI_ASSOC);
$names = $row["name"];
}
$sendObj = new send_message();
if($result1==1)
$sendObj -> send($regid, $names." has Successfully Log In");
else
$sendObj -> send($regid, "Cannot Update");
while($result=$sql->fetch_assoc())
$output[]=$result;
print(json_encode($output));
}// login = true
else
echo "Invalid Username or Password";
}
else{
$sql = "UPDATE tbl_android SET user='-', type='-', lastlog=NOW() WHERE regid='".$regid."'";
$result = mysqli_query(connect(), $sql);
echo "Logged out";
}
?>
请指出我做错了什么,为什么我的页面的响应是一个HTML机器人,谢谢大家btw我使用ipage作为服务器