use*_*610 7 httpclient asp.net-web-api windows-store-apps windows-8.1
我是Web API和Windows Store App 8.1的新手.我正在开发一个与Web API通信的Windows应用商店应用.当我尝试编写以下代码时:
// server:53452/api/demo?ReportingMonth=10&ReportingYear=2013"
using (HttpClient httpClient = new HttpClient())
{
using (HttpResponseMessage response = await httpClient.GetAsync(new Uri("address")))
{
string result = await response.Content.ReadAsStringAsync();
var prodt = JsonConvert.DeserializeObject<ObservableCollection<Statuses>>(result);
return prodt;
}
}
Run Code Online (Sandbox Code Playgroud)
我看到HttpClient同时在Windows.Web.Http和System.Net.Http中.我应该使用哪个命名空间?
如果我选择System.Net.Http命名空间,当我尝试调用启用了Windows身份验证的Web API时,游标将不会返回到客户端,保持未知状态.不知道为什么我没有收到回复.
address = "abc.com:53452/api/demo?ReportingMonth=10&ReportingYear=2013"
using (HttpResponseMessage response = await httpClient.GetAsync(new Uri(address)))
Run Code Online (Sandbox Code Playgroud)
如果我使用HttpClient从Windows.Web.Http,Windows应用商店的应用程序要求我输入凭据,即使我输入了正确的凭据,系统不断提示输入凭据.谁能解释为什么会这样?
要执行 HTTP 身份验证,请不要HttpClientHandler使用HttpBaseProtocolFilter:
var filter = new HttpBaseProtocolFilter();
filter.ServerCredential = new
Windows.Security.Credentials.PasswordCredential(uri.ToString(), "foo", "bar");
var client = new HttpClient(filter);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3038 次 |
| 最近记录: |