0

Web サービスを使用するドロイド アプリを作成しています。文字列を渡すと機能しますが、Xstream を使用しようとすると機能しません。Xstream と自分の両方から xml 文字列を出力しましたが、それらは同一です。xstreamがなければ、このように見えて動作します

`HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("http://softeng.cs.uwosh.edu/students/cs342g6/login.php");
        Boolean response = false;
        try
        {

            String test = "<Login>" +
                    "<password>" + "lernrane" + "</password>" +
                    "<user_name>" + "jake@jake.com" + "</user_name>" +
                    "</Login>";

            StringEntity se = new StringEntity(test,
                    HTTP.UTF_8);
            se.setContentType("text/xml");
            httppost.setEntity(se);
            System.out.println("MADE IT TO RESPONSE");
            HttpResponse httpresponse = httpclient.execute(httppost);
            HttpEntity resEntity = httpresponse.getEntity();
            String resp = EntityUtils.toString(resEntity);
            System.out.println(resp);
            response = convertToBool(resp);`

しかし、xstreamを使用すると、このように見えて失敗します

HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("http://softeng.cs.uwosh.edu/students/cs342g6/login.php");
        Boolean response = false;
        try
        {
            LoginObject login = new LoginObject();
            login.setUserName("jake@jake.com");
            login.setPassword("lernrane");
            XStream xstream = new XStream();
            xstream.alias("Login", LoginObject.class);
            String xml = xstream.toXML(login);
            System.out.println(xml);


            StringEntity se = new StringEntity(xml,
                    HTTP.UTF_8);
            se.setContentType("text/xml");
            httppost.setEntity(se);
            System.out.println("MADE IT TO RESPONSE");
            HttpResponse httpresponse = httpclient.execute(httppost);
            HttpEntity resEntity = httpresponse.getEntity();
            String resp = EntityUtils.toString(resEntity);
            System.out.println(resp);
            response = convertToBool(resp);

私のWebサービスは次のようになります

 $dom = new domDocument;
 $dom = simplexml_load_file('php://input');
 $xml = simplexml_import_dom($dom);
 $user = Users::find_by_user_name($xml->user_name);

 if($user)
 {
if($user->password == $xml->password)
{
    echo "TRUE";
}
 }
 else 
     echo "FALSE";

奇妙に見えるクエリは無視してください。私はアクティブレコードを使用していますが、正しく動作することはわかっています...ありがとう

4

1 に答える 1

-1

私はそれを理解しました...私がxml user_nameを印刷したとき、それは明らかにuser_nameという名前でしたが、このuser__nameのように見えました。ある種の文字セットの競合があるはずなので、アンダースコアなしで名前を変更しました。

于 2013-04-08T01:38:23.057 に答える