首页 > 代码库 > windows phone 8.1 HttpWebRequest 请求服务器
windows phone 8.1 HttpWebRequest 请求服务器
public string SendGetRequest(string baseurl, string parameters) { string parassb = parameters; if (parassb.Length > 0) { baseurl += "?" + parassb; } HttpWebRequest req = (HttpWebRequest)WebRequest.Create(baseurl); req.Method = "GET"; req.ContinueTimeout = 1000; string result = String.Empty; using (StreamReader reader = new StreamReader(req.GetResponseAsync().Result.GetResponseStream())) { result = reader.ReadToEnd(); } return result; }
上面代码是GET方式请求;
public async Task<string> PostRequest(string url, string parameters) { var request = HttpWebRequest.Create(url); request.Method = "POST"; using (Stream result = await request.GetRequestStreamAsync()) { byte[] bytes = Encoding.UTF8.GetBytes(parameters); result.Write(bytes, 0, bytes.Length); } var response = await request.GetResponseAsync(); using (Stream stream = response.GetResponseStream()) { using (StreamReader reader = new StreamReader(stream)) { string content = reader.ReadToEnd(); return content; } } return null; }
这是POST请求方式
windows phone 8.1 HttpWebRequest 请求服务器
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。