我有一個手機應用程序,使用改掉RestSharp如何閱讀在ASP.Net MVC4 API GET請求
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數據,然後想讀取身份驗證的基本授權=新的HttpBasicAuthenticator(「muhcow」,「123456」),當我的api服務器收到這個GET請求時,我可以驗證用戶,但我不知道如何讀取數據。
我有這個
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 ==」