繁体   English   中英

从ios web服务登录android?

[英]android login from ios web service?

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

所以无论如何,这里的问题简而言之。 我有这个Web服务网址的列表
网址列表
从该列表的外观我需要向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”或“真”,以确保我正确连接正确的登录信息。 因此,如果有人有时间看这个问题,我将不胜感激,我理解这是很多阅读。

一些指针 - 您可以考虑使用Robospice,然后使用Android Spring和SimpleXML消息转换器将响应解析为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>

如果您要检查结果, iId0 ,则可能意味着如果用户名和密码不存在则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,然后您可以确定用户是否可以登录。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM