如何使用 Windows Phone 8/8.1 应用程序在 C# 中发送登录凭据并接收 html 页面?
How to send log in credentials and receive a html page in C# using a Windows Phone 8/8.1 app?
我正在尝试访问 html 页面以从我的 Windows Phone 中抓取数据 8. 但首先我需要向它发送登录凭据。我目前正在使用 htmlAgilityPack 从登录页面抓取数据。我曾尝试在后台使用 WebBrowser 实例 运行,但 html 页面无法自动点击,我无法继续。之后,我尝试使用 HttpClient class 通过 PostAsync() 方法发送数据,该方法仅接收 HttpResponseMessage,我不知道该怎么做,但我成功地能够使用HttpContent 对象。
var httpResponseMessage = await client1.PostAsync("https://www.webpage.com", content);
在那之后,我的进步一直很失败。
预先感谢您的帮助。
以下是我如何使用 HttpClient class 与项目中的 Web 服务通信:
public async Task<string> httpPOST(string url, FormUrlEncodedContent content)
{
var httpClient = new HttpClient(new HttpClientHandler());
string resp = "";
HttpResponseMessage response = new HttpResponseMessage();
response = await httpClient.PostAsync(url, content);
try
{
response.EnsureSuccessStatusCode();
Task<string> getStringAsync = response.Content.ReadAsStringAsync();
resp = await getStringAsync;
}
catch (HttpRequestException)
{
resp = "NO_INTERNET";
}
return resp;
}
在这里您可以看到如何检索数据。希望对您有所帮助:)
我正在尝试访问 html 页面以从我的 Windows Phone 中抓取数据 8. 但首先我需要向它发送登录凭据。我目前正在使用 htmlAgilityPack 从登录页面抓取数据。我曾尝试在后台使用 WebBrowser 实例 运行,但 html 页面无法自动点击,我无法继续。之后,我尝试使用 HttpClient class 通过 PostAsync() 方法发送数据,该方法仅接收 HttpResponseMessage,我不知道该怎么做,但我成功地能够使用HttpContent 对象。
var httpResponseMessage = await client1.PostAsync("https://www.webpage.com", content);
在那之后,我的进步一直很失败。 预先感谢您的帮助。
以下是我如何使用 HttpClient class 与项目中的 Web 服务通信:
public async Task<string> httpPOST(string url, FormUrlEncodedContent content)
{
var httpClient = new HttpClient(new HttpClientHandler());
string resp = "";
HttpResponseMessage response = new HttpResponseMessage();
response = await httpClient.PostAsync(url, content);
try
{
response.EnsureSuccessStatusCode();
Task<string> getStringAsync = response.Content.ReadAsStringAsync();
resp = await getStringAsync;
}
catch (HttpRequestException)
{
resp = "NO_INTERNET";
}
return resp;
}
在这里您可以看到如何检索数据。希望对您有所帮助:)