我正在做一个小代码来获取它是否可以连接到数据库。我有几个这样的代码工作,但我不知道为什么我不知道为什么这不起作用。
例外情况如下:
10-24 06:09:08.362: E/Exception:(1753): org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope (position:START_TAG (empty) <br>@1:7 in java.io.InputStreamReader@4176d928)
Java代码:
private final String NAMESPACE = "http://10.0.0.47/fullexample/server.php/";
private final String URL = "http://10.0.0.47/fullexample/server.php";
/*
....
*/
private class get_connectivity extends AsyncTask<String, Integer, String> {
@Override
protected String doInBackground(String... params) {
try{
SoapObject request = new SoapObject(NAMESPACE, "can_connect");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(URL + "/can_connect", envelope);
return "done";
}catch (Exception e){
Log.e("Exception:", e.toString());
}
return "not done";
}
@Override
protected void onPostExecute(String result) {
// got_connection = it's a global string variable
got_connection = result;
}
}
函数 can_connect(在 PHP webservice 中)如下:
function can_connect(){
$host = "localhost";
$user = "root";
$database = "fullexampleDB";
$pwd = "";
$db = new mysqli($host, $user, $pwd, $database);
if ($db->connect_errno) {
return false;
exit();
}
$db->close();
return true;
}
我也总是收到“未完成”的消息。谢谢。