2
我對Android編程相當陌生,所以這可能是一個簡單的問題,但我還沒有找到答案。 基本上,我打電話給期待xml的C#web服務。我很懷疑發送未經過濾的用戶輸入。有相當多的地方,我必須這樣做,但登錄是一個很好的例子:Android用戶輸入清除Web服務電話
這裏是什麼,我現在有一個粗略的版本(從其他SO例子拼湊起來):
String userName = "MyUserName";
String password= "MyPassword";
String url = "http://mywebserviceurl.com/auth;
String xml = "<AuthenticateModel xmlns=\"http://schemas.datacontract.org/2004/07/Mycompany.Auth.Lib\">\n" +
" <EmailAddress>" + userName + "</EmailAddress>\n" +
" <EncodedPassword>" + password + "</EncodedPassword>\n" +
"</AuthenticateModel>";
HttpClient httpclient = new DefaultHttpClient();
HttpPost post = new HttpPost(url);
StringEntity str = new StringEntity(xml);
str.setContentType("application/xml; charset=utf-8");
str.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,"application/xml; charset=utf-8"));
post.setEntity(str);
HttpResponse httpResponse = httpclient.execute(post);
它很好用。用戶信息在服務器端進行處理,但確實將它完全未經過濾發送似乎是個不好的主意。我會很感激反饋。
此外:我將用戶名存儲在應用程序首選項中,所以它不僅僅是我關心的web服務。 謝謝!
謝謝@Rook。我們已經涵蓋了Web服務。如果其他人有任何補充,請做。 – 2012-03-27 20:47:08
@Adrian Carr一個潛在的缺陷是,如果用戶的密碼是「<」。這不是一個安全問題,他只是無法登錄。 – rook 2012-03-28 20:30:05