簡體   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