我正在开发windows phone 8 app。在此应用中,我想使用https
将文件上传到HttpWebRequest
服务器。我该怎么做 ?是否可以从https
服务器上传和下载文件?
我试过这个
private void btnClick_Click(object sender, RoutedEventArgs e)
{
try
{
string url = "https://url/";
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
request.BeginGetResponse(new AsyncCallback(ReadWebRequestCallback), request);
}
catch (Exception ex)
{
}
}
private void ReadWebRequestCallback(IAsyncResult callbackResult)
{
HttpWebRequest myRequest = (HttpWebRequest)callbackResult.AsyncState;
HttpWebResponse myResponse = (HttpWebResponse)myRequest.EndGetResponse(callbackResult);
using (StreamReader httpwebStreamReader = new StreamReader(myResponse.GetResponseStream()))
{
string results = httpwebStreamReader.ReadToEnd();
//TextBlockResults.Text = results; //-- on another thread!
Dispatcher.BeginInvoke(() => MessageBox.Show(results));
}
myResponse.Close();
}
当我调试时,它显示我这样:
获得例外The remote server returned an error: NotFound.
如何从我的Windows Phone 8应用允许 Https
请求?
答案 0 :(得分:1)
当手机“不信任”服务器证书时,这是一个常见问题。如果您将服务器证书安装到手机上,它应该可以正常工作。
将证书保存到您的计算机上(请参阅https://superuser.com/questions/97201/how-to-save-a-remote-server-ssl-certificate-locally-as-a-file)。将其上传到某处(Dropbox,SkyDrive等),您可以在其中获取该文件的公共链接。在手机的IE中打开链接,系统将提示您安装证书。