Windows phone 8 windows phone 8中的http web服务器返回zip文件

Windows phone 8 windows phone 8中的http web服务器返回zip文件,windows-phone-8,webserver,Windows Phone 8,Webserver,您好,我正在我的应用程序中编写http web服务器。 我用了这个密码 此过程可以工作,但在http响应中没有文件的扩展名 返回不带扩展名(.zip)的文件名 private异步任务HandleRequest(StreamSocket) { //初始化IO类 DataReader=新的DataReader(socket.InputStream); reader.InputStreamOptions=InputStreamOptions.Partial; DataWriter writer=新的

您好,我正在我的应用程序中编写http web服务器。 我用了这个密码

此过程可以工作,但在http响应中没有文件的扩展名

返回不带扩展名(.zip)的文件名

private异步任务HandleRequest(StreamSocket)
{
//初始化IO类
DataReader=新的DataReader(socket.InputStream);
reader.InputStreamOptions=InputStreamOptions.Partial;
DataWriter writer=新的DataWriter(socket.OutputStream);
writer.unicode=Windows.Storage.Streams.unicode.Utf8;
//处理实际的HTTP请求
字符串请求=等待StreamReadLine(读卡器);
string[]tokens=request.Split(“”);
if(tokens.Length!=3)
{
抛出新异常(“无效http请求行”);
}
字符串httpMethod=tokens[0].ToUpper();
字符串httpUrl=tokens[1];
//读取HTTP标头-此示例中忽略的内容
而(!String.IsNullOrEmpty(wait StreamReadLine(reader));
尝试
{
如果(httpUrl==“DOWNLOADZIP”)
{
使用(IsolatedStorageFile storage=IsolatedStorageFile.GetUserStoreForApplication())
{
字符串内容=null;
溪流;
字节[]数据;
IsolatedStorageFileStream sri=storage.OpenFile(“CompressedFiles.zip”,FileMode.Open,FileAccess.Read);
如果(空!=sri)
{
stream=sri;
数据=新字节[stream.Length];
读取(数据,0,数据长度);
writer.writebytes(数据);
}
}
}
}
catch(Exception ex)//任何异常都会导致内部服务器错误
{
writer.WriteString(“HTTP/1.0 500内部服务器错误\r\n”);
writer.WriteString(“连接:关闭\r\n”);
writer.WriteString(“\r\n”);
writer.WriteString(例如消息);
}
}
等待writer.StoreAsync()//将数据实际写入网络接口
socket.Dispose();
返回null;
}
这是一个解决方案

ret.AppendLine("HTTP/1.0 200 OK");
ret.AppendLine("Content-Type: text/html");
ret.AppendLine("Connection: close");
ret.AppendLine("");
ret.AppendLine("Content-Disposition: attachment; filename=myfile.zip");
ret.AppendLine("HTTP/1.0 200 OK");
ret.AppendLine("Content-Type: text/html");
ret.AppendLine("Connection: close");
ret.AppendLine("");
ret.AppendLine("Content-Disposition: attachment; filename=myfile.zip");