当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - [Windows Phone]-How to save cookie/session in webclient

问题描述:

I'm trying create a windows phone application, get data from server using an api by webclient. It's have to make 2 steps:

  1. Send the first request with public key to verify with server. The response contain message, if "Valid key", the session was created within 15 minutes.

{"code":200,"content":null,"message":"Valid key"} or

{"code":401,"content":null,"message":"Invalid key"}.

  1. Next, after receive message "Valid key", going to send the second request to get data.


The API working correctly with web browser on PC

{

code: 200,

content: null,

message: "Valid key"

}

{

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

},

But when i send the 2nd request using webclient in code, always response message "Access denied"

 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":"Access denied"}

May be the webclient in windows phone does'nt save the seesion/cookies after the first request.

分享给朋友:
您可能感兴趣的文章:
随机阅读: