好吧,我试图用c#在Windows Phone 8中保存网页的html,我在互联网上找到的所有解决方案都不起作用,无论如何我可以保存html的内容windows phone 8.我尝试过的一些解决方案
using System.Net;
using System.Net.Http;
var httpClient = new HttpClient();
var message = new HttpRequestMessage(HttpMethod.Get, targetURL);
//message.Headers.Add(....);
//message.Headers.Add(....);
var response = await httpClient.SendAsync(message);
if (response.StatusCode == HttpStatusCode.OK)
{
//HTTP 200 OK
var requestResultString = await response.Content.ReadAsStringAsync();
}
// HttpClient() is not there
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(URL);
myRequest.Method = "GET";
using(WebResponse myResponse = myRequest.GetResponse() )
{
using(StreamReader sr = new StreamReader(myResponse.GetResponseStream(), System.Text.Encoding.UTF8))
{
string result = sr.ReadToEnd();
}
}
// System.Net.HttpWebRequest' does not contain a definition for 'GetResponse' and no extension method 'GetResponse' accepting a first argument of type 'System.Net.HttpWebRequest' could be found (are you missing a using directive or an assembly reference?)
答案 0 :(得分:0)
如果要在Windows Phone 8中使用HttpClient,则必须安装NuGet包。搜索httpclient
。
然后你可以使用
System.Net.Http.HttpClient myHttp = new System.Net.Http.HttpClient();