我有使用REST服务访问数据库登录用户的安全问题,我有它的工作,但我知道它不能这样,因为密码不是以任何方式编写和通过URL旅行。这是我的代码:如何隐藏基于REST的服务中的帐户信息?
首先,发送请求的代码:
private void validateUser(String user, String pass)
{
String URL = "http://myserviceserver/MyService.svc";
AlertDialog popup;
try{
HttpGet request = new HttpGet(URL + "/Validate" + "/" + user + "/" + pass);
request.setHeader("Accept", "application/json");
request.setHeader("Content-type", "application/json");
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpResponse response = httpClient.execute(request);
HttpEntity responseEntity = response.getEntity();
// Read response data into buffer
char[] buffer = new char[(int)responseEntity.getContentLength()];
InputStream stream = responseEntity.getContent();
InputStreamReader reader = new InputStreamReader(stream);
reader.read(buffer);
stream.close();
String resultado = new String(buffer);
if(resultado.contains("true"))
{
popup = createAlertDialog("Message", "User Validated", "OK");
popup.show();
}
else
{
popup = createAlertDialog("Message", "User NOT Validated", "OK");
popup.show();
}
}
catch(Exception e)
{
}
}
现在,从服务器端,这是我的服务接口:
[ServiceContract]
public interface IMyService
{
[OperationContract]
[WebInvoke(Method = "GET", UriTemplate = "Create/{user}/{pass}/{email}")]
bool CreateNewAccount(string user, string pass, string email);
[OperationContract]
[WebInvoke(Method = "GET", UriTemplate = "Validate/{user}/{pass}")]
bool ValidateUser(string user, string pass);
}
现在,这就像一个魅力,但它是不安全的,但我不太明白我怎么能隐藏发送的信息,因为现在我只需在http://myserviceserver/MyService.svc/Validate/user/password提出请求登录。
任何帮助将apreciated :)
为什么不使用内置到WCF中的函数进行身份验证?这样你就不必用头文件和东西重新实现整个HTTP客户端,只需使用WCF并将其配置为使用wsHttp即可。 – CodeCaster