php - 从 ios Web 服务登录 android?

标签 php android ios web-services

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

所以无论如何,这里是问题的简而言之。我有这个网络服务 url 的列表
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. 以上所有和/或其他

现在,通过查看当前的 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>

如果您要检查结果,iId0,这可能意味着 iId 设置为零,如果用户名和密码不存在,因为最初,ids 以 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,就可以判断用户是否可以登录了.

关于php - 从 ios Web 服务登录 android?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16752562/

相关文章:

php - 提高PHP Mysql中网页的处理速度

php - 如何检查一个字符串是否已经存在于mysql中(所有词序选项)?

android - Android 版 Swift : `ld` cannot find `-lgcc` in swift for android compilation linking step

javascript - Cordova CORS 调用无法正常工作

ios - NSUserDefaults(套件名称 :) on iOS 9 and WatchOS 2 - not working?

iOS:用多种字体和文本样式显示长页面内容

php - 将 WooCommerce Ajax 上的产品 ID、名称和数量添加到购物车以显示通知

php - 在提交时插入 MySQL 数据

java - 从自定义 View 调用 findViewById 返回 null

ios - 当应用程序进入前台时将 iOS 应用程序与 ALAssetsLibrary 同步的最佳方式