2009-12-30 28 views
3

HttpWebRequest上的MediaType屬性的有效值是什麼?什麼是HttpWebRequest上的MediaType屬性的有效值

我想要做這樣的事情:

Dim url As String = HttpContext.Current.Request.Url.AbsoluteUri 
Dim req As System.Net.HttpWebRequest = DirectCast(System.Net.WebRequest.Create(New Uri(url)), System.Net.HttpWebRequest) 
' Add the current authentication cookie to the request 
Dim cookie As HttpCookie = HttpContext.Current.Request.Cookies(FormsAuthentication.FormsCookieName) 
Dim authenticationCookie As New System.Net.Cookie(FormsAuthentication.FormsCookieName, cookie.Value, cookie.Path, HttpContext.Current.Request.Url.Authority) 

req.CookieContainer = New System.Net.CookieContainer() 
req.CookieContainer.Add(authenticationCookie) 
req.MediaType = "PRINT" 

Dim res As System.Net.WebResponse = req.GetResponse() 
'Read data 
Dim ResponseStream As Stream = res.GetResponseStream() 
'Write content into the MemoryStream 
Dim resReader As New BinaryReader(ResponseStream) 
Dim docStream As New MemoryStream(resReader.ReadBytes(CInt(res.ContentLength))) 

感謝。

+0

至少它分開到兩個問題,所以不會太本地化,而不是由他人使用。 –

+0

我唯一的問題是「什麼是HttpWebRequest的MediaType屬性的有效值?」剩下的就是我如何使用它。對不起,如果不明確。 –

回答

4

我覺得這個維基百科頁面應該給你的媒體類型相當全面的清單:
Media Types

相關問題