Php 从ios网络服务登录android?
我正在尝试将Php 从ios网络服务登录android?,php,android,ios,web-services,Php,Android,Ios,Web Services,我正在尝试将Android应用程序连接到最初为iOS设计的web服务,我不确定这是否可行。我也没有设计这个web服务,所以我正在浏览这个不是我的代码,只是在摸索。当前web服务是用PHP编写的,并使用SOAP和WSDL。如果我可以连接到此web服务,我将尝试使用ksoap2,除非我找到更好的替代方案。我将在这篇文章中使用很多链接,因为如果没有它们,你将看到大量令人讨厌的代码 总之,问题就在这里。我有此web服务url的列表 从该列表的外观来看,我需要向iphoneview/iphone\u ge
Android
应用程序连接到最初为iOS
设计的web服务,我不确定这是否可行。我也没有设计这个web服务,所以我正在浏览这个不是我的代码,只是在摸索。当前web服务是用PHP
编写的,并使用SOAP
和WSDL
。如果我可以连接到此web服务,我将尝试使用ksoap2
,除非我找到更好的替代方案。我将在这篇文章中使用很多链接,因为如果没有它们,你将看到大量令人讨厌的代码
总之,问题就在这里。我有此web服务url的列表从该列表的外观来看,我需要向iphoneview/iphone\u get\u details.php发出登录请求,其中包含以下内容
但是,当我使用此代码时
class LogMeIn extends AsyncTask<String, Void, String> {
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(
"http://www.fakesite.com/myv2/iphoneview/iphone_get_details.php");
protected String doInBackground(String... urls) {
try {
username = un.getText().toString();
password = pw.getText().toString();
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(
2);
nameValuePairs
.add(new BasicNameValuePair("username", username));
nameValuePairs
.add(new BasicNameValuePair("password", password));
post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = client.execute(post);
String res = inputStream(response.getEntity().getContent())
.toString();
Log.v("RESPONSE", res);
// if username and password are valid, launch main activity
if (res.toString() == "1") {
Intent logIn = new Intent(getApplicationContext(),
Main.class);
startActivity(logIn);
}
// send the user a message saying the login failed
else {
runOnUiThread(new Runnable() {
public void run() {
pw.setText("");
fail.setText(R.string.fail);
}
});
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String file_url) {
}
}
类LogMeIn扩展了异步任务{
HttpClient=new DefaultHttpClient();
HttpPost=新的HttpPost(
"http://www.fakesite.com/myv2/iphoneview/iphone_get_details.php");
受保护的字符串doInBackground(字符串…URL){
试一试{
username=un.getText().toString();
password=pw.getText().toString();
List name valuepairs=new ArrayList(
2);
nameValuePairs
.添加(新的BasicNameValuePair(“用户名”,用户名));
nameValuePairs
.add(新的BasicNameValuePair(“密码”,password));
setEntity(新的UrlEncodedFormEntity(nameValuePairs));
HttpResponse response=client.execute(post);
String res=inputStream(response.getEntity().getContent())
.toString();
Log.v(“响应”,res);
//如果用户名和密码有效,则启动主活动
如果(res.toString()=“1”){
意图登录=新意图(getApplicationContext(),
主要类别),;
startActivity(登录);
}
//向用户发送一条消息,说明登录失败
否则{
runOnUiThread(新的Runnable(){
公开募捐{
pw.setText(“”);
setText(R.string.fail);
}
});
}
}捕获(例外e){
e、 printStackTrace();
}
返回null;
}
受保护的void onPostExecute(字符串文件\u url){
}
}
我得到的只是一个回应
05-25 13:57:21.292: V/RESPONSE(5871): <?xml version='1.0' encoding='UTF-8'?><!DOCTYPE plist PUBLIC '-//Apple//DTD PLIST 1.0//EN' 'http://www.apple.com/DTDs/PropertyList-1.0.dtd'><plist version='1.0'><dict><key>iId</key><string>0</string><key>itemChildren</key><array></array></dict></plist>
05-2513:57:21.292:V/应答(5871):IID0项目儿童
我知道这种反应来自哪里,iphoneview/iphone\u get\u details.php的最底层。问题是我不知道是不是因为
SOAP
请求中现在常识告诉我,通过查看当前的iphone_get_details.php文件,无论哪种方式,我都不会收到“1”或“true”的响应。事实上,该文件看起来像是发回了大量信息,而实际上我想要的只是一个“1”或“true”,以确保我正确连接了正确的登录信息。因此,如果有人有时间仔细考虑这个问题,我将不胜感激,我知道这需要大量阅读>一些指针——您可以考虑使用RoopSoice,然后使用Android Spring和SimulXML消息转换器解析响应到java POJO中。您得到的回应是iphone plist的XML,在Android环境中使用它将是一个挑战,但并非不可能。服务器的响应与您的Android代码无关,因此您应该能够使用web浏览器验证它是否与发送到iPhone应用程序的内容相同 希望这能给你一些展望的空间和前进的动力
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE plist PUBLIC '-//Apple//DTD PLIST 1.0//EN'http://www.apple.com/DTDs/PropertyList-1.0.dtd'>
<plist version='1.0'>
<dict>
<key>iId</key>
<string>0</string>
<key>itemChildren</key>
<array></array>
</dict>
</plist>
对于结果,您只需解析返回的xml并获取
iId
值,然后检查它是否为0,然后您就可以确定用户是否可以登录。这是个不幸的消息。我真的希望我能使用这个代码。我的直觉告诉了我你刚刚发布的内容。我花了一个星期的时间来处理这件事。我需要咬紧牙关,然后为这个应用程序编写自己的PHP。在我看来,这会更快,尤其是在处理测试/调试时。我会等一等,看看是否有其他人有不同的反应,否则我会接受这个答案,继续我的生活。结果是问题的一部分,但很小。我可以处理实际的反应,不管它是什么。我认为这根本不是对我文章的回应,我认为这只是一个回应,因为一个非iOS移动设备正在尝试访问此信息。感谢您的辛勤工作。我决定创建自己的web服务。从长远来看,无论如何更新/维护都会容易得多。答案已被接受,明天计时器启动时将颁发奖金。欢迎您,如果您能够创建自己的Web服务,那就太好了,它更容易理解,并且可以为您节省大量时间。:)
$vUserName = stripslashes(trim($_REQUEST["txtUser"]));
$vPassword = stripslashes(trim($_REQUEST["txtPass"]));
$returnFinalString = "";
$member_id = 0;
.
.
.
//if this condition is true, meaning, the username and password matched and exist
if(mysql_num_rows($member_res)>0){
$member_id = $mem_row['user_id'];
}
//and the $member_id is changed to non-zero