如何使用 wp7 BackgroundTransferService 上传图像并获取服务器响应?
var transferRequest = new BackgroundTransferRequest(new Uri(Global.profileUploadServerUrl, UriKind.Absolute));
transferRequest.Method = "POST";
transferRequest.UploadLocation = new Uri(@"/shared\transfers/file.jpg", UriKind.Relative);
transferRequest.TransferPreferences = TransferPreferences.AllowCellularAndBattery;
transferRequest.Headers["Content-Type"] = "multipart/form-data";
transferRequest.TransferStatusChanged += new EventHandler<BackgroundTransferEventArgs>(transferRequest_TransferStatusChanged);
transferRequest.TransferProgressChanged += new EventHandler<BackgroundTransferEventArgs>(transferRequest_TransferProgressChanged);
BackgroundTransferService.Add(transferRequest);
static void transferRequest_TransferProgressChanged(object sender, BackgroundTransferEventArgs e)
{
// throw new NotImplementedException();
}
static void transferRequest_TransferStatusChanged(object sender, BackgroundTransferEventArgs e)
{
BackgroundTransferRequest request = sender as BackgroundTransferRequest;
if (request.TransferStatus == TransferStatus.Completed)
{
BackgroundTransferService.Remove(request);
if (request.StatusCode == 201)
{
MessageBox.Show("Upload completed.");
}
else
{
MessageBox.Show("An error occured during uploading. Please try again later." + request.StatusCode.ToString() + "/ " + request.TransferError);
}
}
}
图像加载似乎通过了,但服务器返回状态 206。以及如何从服务器获得响应?这里看了示例,但我不明白。 在这个例子中,有一行:
request.DownloadLocation = new Uri (responsePath, UriKind.RelativeOrAbsolute);
那有必要指定吗?如果我这样做,它将指定相同的 url,它会失败。一般来说,卸载图像服务器后的想法应该返回带有图像链接的响应。但他会出来答案 206。如何得到答案?