EasyHttp/EasyHttp:Http Library for C#
An easy to use HTTP client that supports:
class CaptchaImageInfo
{
public string uuid;
public string img;
}
HttpClient http = new HttpClient();
http.Request.Accept = HttpContentTypes.ApplicationJson;
http.Request.ContentType = HttpContentTypes.ApplicationJson;
var response = http.Get("http://localhost:8080/captchaImage");
var captchaImageInfo = response.StaticBody<CaptchaImageInfo>();
uuid = captchaImageInfo.uuid;
Console.WriteLine("uuid: {0}", captchaImageInfo.uuid);
Console.WriteLine("img: {0}", captchaImageInfo.img);
class TokenInfo
{
public string token;
public string code;
public string msg;
}
HttpClient http = new HttpClient();
http.Request.Accept = HttpContentTypes.ApplicationJson;
http.Request.ContentType = HttpContentTypes.ApplicationJson;
var response = http.Get("http://localhost:8080/v3/admin/system/user/login/status", new { uuid=uuid });
var tokenInfo = response.StaticBody<TokenInfo>();
Console.WriteLine("token: {0}, code: {1}, msg: {2}", tokenInfo.token, tokenInfo.code, tokenInfo.msg);
class AccountLoginInfo
{
public string username;
public string phoneNumber;
public string password;
public string code;
public string uuid;
}
HttpClient http = new HttpClient();
http.Request.Accept = HttpContentTypes.ApplicationJson;
http.Request.ContentType = HttpContentTypes.ApplicationJson;
var accountLoginInfo = new AccountLoginInfo();
accountLoginInfo.username = usernameText.Text.ToString();
accountLoginInfo.password = pwdText.Text.ToString();
accountLoginInfo.code = verificateCodeText.Text.ToString();
accountLoginInfo.uuid = uuid;
var response = http.Post("https://localhost:8080/v3/admin/system/user/login/password", accountLoginInfo, HttpContentTypes.ApplicationJson);
Console.WriteLine(response.RawText);
if (response.StatusCode != HttpStatusCode.OK)
{
MessageBox.Show("异常");
}
var tokenInfo = response.StaticBody<TokenInfo>();
if (tokenInfo.code.Equals("200"))
{
Console.WriteLine("token: {0}, code: {1}, msg: {2}", tokenInfo.token, tokenInfo.code, tokenInfo.msg);
http.Request.RawHeaders.Add("Authorization", tokenInfo.token);
MessageBox.Show("登录成功");
this.Close();
}
else
{
MessageBox.Show(tokenInfo.msg);
}
http.Request.RawHeaders.Add("Authorization", token);
觉得好,就一键三连呗(点赞+收藏+关注)