我有一个电话应用程序尝试使用 RestSharp 从我的网络 api 获取数据
private void ButtonTestTap(object sender, EventArgs e)
{
var client = new RestClient
{
CookieContainer = new CookieContainer(),
BaseUrl = "http://localhost:21688/api/game",
Authenticator = new HttpBasicAuthenticator("muhcow", "123456")
};
RestRequest request = new RestRequest(Method.GET);
request.AddParameter("id", 5);
//request.AddBody(5);
client.GetAsync<LoginResult>(request, (response, ds) =>
{
System.Diagnostics.Debug.WriteLine(response.StatusDescription);
System.Diagnostics.Debug.WriteLine(response.Data);
System.Diagnostics.Debug.WriteLine(response.Content);
});
}
然后想在我的 api 服务器收到此 GET 请求时读取 Authenticator = new HttpBasicAuthenticator("muhcow", "123456") 以便我可以验证用户,但我不确定如何读取数据。
我有这个
public class GameController : ApiController
{
// GET /api/game/5
public string Get(int id)
{
var sdf2 = ControllerContext.Request.Headers.Authorization.Parameter;
//return LoginManager.VerifyLogin(loginData);
return "Some data";
}
但是 sdf2 只是有一个奇怪的值 "bXVoY293OjEyMzQ1Ng=="