从ios web服务登录android?

时间:2013-05-25 18:14:38

标签: php android ios web-services

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

所以,总之这里的问题简直就是问题。我有这个网站服务网址列表 URL List
从该列表的外观我需要向 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. 以上所有内容和/或其他内容
  5. 现在常识通过查看当前的iphone_get_details.php文件告诉我,无论如何我都不会收到“1”或“true”的响应。事实上,文件看起来像发回大量信息,实质上我想要的只是“1”或“真”,以确保我正确连接正确的登录信息。因此,如果有人有时间看这个问题,我将不胜感激,我理解这是很多阅读。

2 个答案:

答案 0 :(得分:1)

一些指针 - 您可以考虑使用Robospice,然后使用Android Spring和SimpleXML消息转换器将响应解析为Java POJO。您要回复的响应是iphone plist的XML,这对于在Android环境中使用来说将是一项挑战,但并非不可能。服务器的响应与您的Android代码无关,因此您应该能够验证它与使用Web浏览器发送到iPhone应用程序的内容相同。

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

答案 1 :(得分:1)

<?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开头,或者可能是数据库中用户的iId0,那么您可以说数据库中匹配的用户名和密码就意味着用户提供的密码和用户名是正确的,反之亦然。

编辑:::

我已在此处检查了您的链接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,然后您可以确定用户是否可以登录。

相关问题