HttpClient Get请求:
/// <summary>
/// Get请求模拟
/// </summary>
/// <param name="url">请求URL</param>
public void HttpRequest(string url)
{
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
Task<HttpResponseMessage> response = client.GetAsync(url);
HttpResponseMessage result = response.Result;
this.queryResultPane.Text = result.Content.ReadAsStringAsync().Result;
}
HttpClient Post请求:
var aaa = new
{
Code = "139357a4-b38c-483e-a530-8f044a3dfe1c",
WechatOpenID = "33265198",
Area = "ShangHai",
Birthday = DateTime.Parse("1986-8-18"),
Gender = "male",
Level = 80,
Name = "Lynn",
PhoneNumber = "13129623023",
EmailType = "qq",
IsHaveParent = "no",
Province = "河南省",
TheCity = "郑州市",
//Age = 100,
Labels = new List<LabelEntity>() { new LabelEntity() { Label = "uuuu" }, new LabelEntity() { Label = "yyyy" } }
};
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
//简单类型的参数,webApi方法里可以不定义参数,通过HttpContext.Current.Request.QueryString["Mobile"]来获取
Task<HttpResponseMessage> response =
//client.PostAsJsonAsync<ThreeMMember>(string.Format(U8688 + "MemberPoint/UpdateMemberInfo"), member);
client.PostAsJsonAsync(string.Format(U8688 + "MemberPoint/SaveMember"), aaa);
HttpResponseMessage result = response.Result;
this.Response.Output.Write(result.Content.ReadAsStringAsync().Result);