我正在用.NET创建一个服务器,并为Android创建一个客户端应用程序.我想实现一种身份验证方法,它将用户名和密码发送到服务器,而服务器发回会话字符串.
我不熟悉水渍险,所以我会非常感谢你的帮助.
在java中,我编写了以下方法:
private void Login()
{
HttpClient httpClient = new DefaultHttpClient();
try
{
String url = "http://192.168.1.5:8000/Login?username=test&password=test";
HttpGet method = new HttpGet( new URI(url) );
HttpResponse response = httpClient.execute(method);
if ( response != null )
{
Log.i( "login", "received " + getResponse(response.getEntity()) );
}
else
{
Log.i( "login", "got a null response" );
}
} catch (IOException e) {
Log.e( "error", e.getMessage() );
} catch (URISyntaxException e) {
Log.e( "error", e.getMessage() );
}
}
private String getResponse( HttpEntity entity )
{
String response = "";
try
{
int length = ( int ) entity.getContentLength();
StringBuffer sb = new StringBuffer( length );
InputStreamReader isr = new InputStreamReader( entity.getContent(), "UTF-8" );
char buff[] = new char[length];
int cnt;
while ( ( cnt = isr.read( buff, 0, length - 1 ) ) > 0 )
{
sb.append( buff, 0, cnt );
}
response = sb.toString();
isr.close();
} catch ( IOException ioe ) {
ioe.printStackTrace();
}
return response;
}
但在服务器端,到目前为止我还没有找到任何答案.
如果有人能解释如何用合适的应用程序创建合适的方法字符串登录(字符串用户名、字符串密码),我将非常感激.配置设置并与适当的[OperationContract]签名交互,以便从客户端读取这两个参数并使用会话字符串进行回复.
谢谢