Android登录从ios web服务


android login from ios web service?

我正试图将Android应用程序连接到最初为iOS设计的web服务,我不确定它是否可能。我也没有设计这个web服务,所以我正在寻找这不是我的代码,只是一种摸索。当前的web服务是用PHP编写的,使用SOAPWSDL。如果我能连接到这个web服务,我会尝试使用ksoap2,除非我找到一个更好的替代方案。我将在这篇文章中使用大量的链接,因为如果没有它们,你将看到大量令人讨厌的代码。

总之,这是一个简单的问题。我有一个web服务url的列表
URL列表
和从该列表的外观,我需要使我的登录请求到iphoneview/iphone_get_details.php这里面有这个。
get_details
但是当我使用这段代码时

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) {
    }
}

我得到的只是这个响应

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>

我知道这个响应来自哪里,有非常底部的iphoneview/iphone_get_details.php。问题是我不知道是不是因为

  1. 我需要在SOAP请求中包装这个
  2. 我不能使用这个代码
  3. 我连接到错误的文件(怀疑)
  4. 以上所有内容和/或其他内容

现在,常识告诉我,从查看当前的iphone_get_details.php文件,我将不会收到"1"或"true"的响应。事实上,该文件看起来像是返回了大量信息,而实际上我想要的只是一个"1"或"true",以确保我正确地连接到正确的登录信息。如果有人有时间看一下这个问题,我会很感激,我知道这需要大量的阅读。

<?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>

如果你要检查结果,iId 0,它可能意味着iId设置为零,如果用户名和密码不存在,因为最初,ids's始于1或可能是数据库中的用户的iId 0那时你可以说数据库中的用户名和密码匹配,意味着用户提供的密码和用户名是正确的或者反过来。

编辑:::

我在这里检查了您的链接http://pastebin.com/8vv1Vvxj,根据代码和返回的xml,如果没有匹配的用户名和密码,则表示iId的默认值为0,否则如果iId不为0则表示用户名和密码正确。

php的初始值

$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

对于结果,您只需要解析返回的xml并获得iId值并检查它是否为0,然后您可以确定用户是否可以登录。

一些指针——你可以考虑使用Robospice,然后使用Android Spring和SimpleXML消息转换器将响应解析为Java POJO。您得到的响应是用于iphone plist的XML,这在Android环境中是具有挑战性的,但并非不可能。来自服务器的响应与你的Android代码无关,所以你应该能够通过使用web浏览器来验证它是否与发送到iPhone应用程序的内容相同。

希望这能给你一些地方看和一些前进的动力。