我正在尝试创建一个Windows Phone应用程序,通过webclient使用api从服务器获取数据。它必须做两个步骤:
{“code”:200,“content”:null,“message”:“有效密钥”} 或 {“code”:401,“content”:null,“message”:“无效密钥”}。
API可正常使用PC上的网络浏览器
{ 代码:200, 内容:null, 消息:“有效密钥” }
{
code: 200,
content: {
topics: [
{
absViewUrl: "http://www.depvd.com/view/Chan-Dai-Xu-Han-Xinh-Ghe/TLcfZPtUUe",
absWidgetImage: "http://photo.depvd.com/13/317/08/ph_o1SJotZgie_OIusQYb2_wi.jpg",
commentsCount: 0,
likeCount: 0,
models: [
{
absModelUrl: "http://www.depvd.com/model/Choi-Byeol-Yee/2sj1OYbIsN",
name: "Choi Byeol Yee"
}
],
photos: [
{
absNormal: "http://photo.depvd.com/13/317/08/ph_o1SJotZgie_OIusQYb2_no.jpg"
}
],
title: "Chân dài xứ Hàn xinh ghê",
user: {
absUserUrl: "http://www.depvd.com/user/Takei-Emi/o1SJotZgie",
displayName: "Takei Emi"
},
viewCount: 17
},
但是当我在代码中使用webclient发送第二个请求时,总是响应消息“拒绝访问”
public void GetAlbum(int page)
{
string url = "http://open-api.depvd.com/Topic/GetNewTopics?page=1";
WebClient webClient = new WebClient();
webClient.Headers["Accept"] = "application/json";
webClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(AlbumDownloaded);
webClient.DownloadStringAsync(new Uri(url, UriKind.RelativeOrAbsolute));
}
{“code”:401,“content”:null,“message”:“拒绝访问”}
可能是Windows Phone中的webclient在第一次请求后没有保存seeion / cookies。