我是一名 Windows Phone 开发人员。我刚刚开始使用异步调用。这是我获取一些元数据的代码。关于它的几点:
- 我在另一个方法回调中调用了 getmetadata()
- 我希望
cskeys
有 5 个值 - 我检查了我得到 jsessionid
- 我检查了我正在获取 sessioncookie
有两个功能,GetMetaData
和GetFolder_MetadataCallback
:
private void GetMetadata()
{
try
{
foreach (string folderpath in CSKeys)
{
if (!string.IsNullOrEmpty(folderpath))
{
HttpWebRequest FolderMetadataRequest = (HttpWebRequest)WebRequest.Create(new Uri(URL + folderpath));
FolderMetadataRequest.Method = DisplayMessage.HeadMethod;
FolderMetadataRequest.Headers[DisplayMessage.Header_Authorization] = Authentication_Parameters[DisplayMessage.Username] + DisplayMessage.Colon +
Authentication_Parameters[DisplayMessage.JSessionID];
FolderMetadataRequest.Headers[DisplayMessage.Header_Cookie] = Authentication_Parameters[DisplayMessage.SessionCookie];
FolderMetadataRequest.BeginGetResponse(new AsyncCallback(GetFolder_MetadataCallback), FolderMetadataRequest);
}
}
}
catch (Exception ex)
{
}
}
private void GetFolder_MetadataCallback(IAsyncResult asynchronousResult)
{
try
{
HttpWebRequest FolderReq = (HttpWebRequest)asynchronousResult.AsyncState;
HttpWebResponse FolderResponse = (HttpWebResponse)FolderReq.EndGetResponse(asynchronousResult);
if (FolderResponse.StatusCode == HttpStatusCode.OK)
{
System.Net.WebHeaderCollection folderMedataCollection = FolderResponse.Headers;
Dictionary<string, string> FolderMetadata_Header = new Dictionary<string, string>();
FolderMetadata_Header.Add(DisplayMessage.UniqueID_Key, folderMedataCollection[DisplayMessage.UniqueID_Value]);
FolderMetadata_Header.Add(DisplayMessage.Actual_Name_Key, folderMedataCollection[DisplayMessage.Actual_Name_Value]);
FolderMetadata_Header.Add(DisplayMessage.Display_Name_Key, folderMedataCollection[DisplayMessage.Display_Name_Value]);
FolderMetadata_KeyValues.Add(FolderPath, FolderMetadata_Header);
}
app.Storage_Parameters.Add(DisplayMessage.Metadadata_StorageKey, FolderMetadata_KeyValues);
}
catch (Exception ex)
{
}
}
对于第一个,第二个和第三个,keyvalue(CSKey)
我得到了回应。我得到了所有的值,它也被添加到了FolderMetadata_Keyvalues
。有时对于第四个和第五个键(CSKey)我得到一个Value cannot be null parameter
例外。为什么?