返回信息流#if NET_2_1
using System;
using System.Collections;
using System.Globalization;
using System.IO;
using System.Net;
using System.Windows.Interop;
using Mono;
namespace System.Windows.Browser.Net
{
class BrowserHttpWebRequest : HttpWebRequest
{
IntPtr native;
Uri uri;
string method = "GET";
WebHeaderCollection headers = new WebHeaderCollection ();
MemoryStream request;
BrowserHttpWebResponse response;
BrowserHttpWebAsyncResult async_result;
public BrowserHttpWebRequest (Uri uri)
{
this.uri = uri;
}
~BrowserHttpWebRequest ()
{
if (async_result != null)
async_result.Dispose ();
if (native == IntPtr.Zero)
return;
NativeMethods.browser_http_request_destroy (native);
}
public override void Abort ()
{
if (native == IntPtr.Zero)
return;
NativeMethods.browser_http_request_abort (native);
}
static bool IsSameRangeKind (string range, string rangeSpecifier)
{
return range.ToLower (CultureInfo.InvariantCulture).StartsWith (
rangeSpecifier.ToLower (CultureInfo.InvariantCulture));
}
public override IAsyncResult BeginGetRequestStream (AsyncCallback callback, object state)
{
throw new NotImplementedException ();
}
public override IAsyncResult BeginGetResponse (AsyncCallback callback, object state)
{
InitializeNativeRequest ();
async_result = new BrowserHttpWebAsyncResult (callback, state);
if (!NativeMethods.browser_http_request_get_async_response (native, OnAsyncResponseAvailable, IntPtr.Zero))
throw new InvalidOperationException ();
return async_result;
}
void OnAsyncResponseAvailable (IntPtr native, IntPtr context)
{
try {
async_result.Response = new BrowserHttpWebResponse (this, native);
async_result.SetComplete ();
} catch (Exception e) {
async_result.Exception = e;
}
}
public override Stream EndGetRequestStream (IAsyncResult asyncResult)
{
throw new NotImplementedException ();
}
public override WebResponse EndGetResponse (IAsyncResult asyncResult)
{
if (async_result != asyncResult)
throw new ArgumentException ();
if (!async_result.IsCompleted)
async_result.AsyncWaitHandle.WaitOne ();
if (async_result.HasException) {
async_result.Dispose ();
throw async_result.Exception;
}
response = async_result.Response;
async_result.Dispose ();
response.Read ();
return response;
}
public Stream GetRequestStream ()
{
if (request == null)
request = new MemoryStream ();
return request;
}
static Uri GetBaseUri ()
{
//FIXME: there's most probably a better way to do this.
string uri = HtmlPage.DocumentUri.AbsoluteUri;
return new Uri (uri.Substring (0, uri.LastIndexOf ("/") + 1));
}
static Uri GetAbsoluteUri (Uri uri)
{
return new Uri (GetBaseUri (), uri);
}
void InitializeNativeRequest ()
{
if (native != IntPtr.Zero)
return;
Uri request_uri = uri.IsAbsoluteUri ? uri : GetAbsoluteUri (uri);
native = NativeMethods.browser_http_request_new (PluginHost.Handle, method, request_uri.AbsoluteUri);
if (native == IntPtr.Zero)
throw new NotSupportedException ("Failed to create unmanaged BrowserHttpRequest object. unsupported browser.");
foreach (string header in headers.Headers)
NativeMethods.browser_http_request_set_header (native, header, headers [header]);
if (request != null && request.Length > 0) {
byte [] body = request.ToArray ();
NativeMethods.browser_http_request_set_body (native, body, body.Length);
}
}
public HttpWebResponse GetResponse ()
{
InitializeNativeRequest ();
IntPtr resp = NativeMethods.browser_http_request_get_response (native);
if (resp == IntPtr.Zero)
throw new InvalidOperationException ();
response = new BrowserHttpWebResponse (this, resp);
response.Read ();
return response;
}
public override string ContentType {
get { return headers [HttpRequestHeader.ContentType]; }
set { headers [HttpRequestHeader.ContentType] = value; }
}
public override bool HaveResponse {
get { return response != null; }
}
public override WebHeaderCollection Headers {
get { return headers; }
set { headers = value; }
}
public override string Method {
get { return method; }
set { method = value; }
}
public override Uri RequestUri {
get { return uri; }
}
}
}
#endif
文件名是: BrowserHttpWebRequest.cs
编译的时候提示错误:
./System.Windows.Browser.Net/BrowserHttpWebRequest.cs(42,16): error CS0534: `System.Windows.Browser.Net.BrowserHttpWebRequest' does not implement inherited abstract member `System.Net.WebRequest.GetRequestStream()'
./System.Windows.Browser.Net/BrowserHttpWebRequest.cs(42,16): error CS0534: `System.Windows.Browser.Net.BrowserHttpWebRequest' does not implement inherited abstract member `System.Net.WebRequest.GetResponse()'
明明已经写了public Stream GetRequestStream () 和 public HttpWebResponse GetResponse () 这两个方法,为什么还提示这个错误呢?
这是一条镜像帖。来源:北邮人论坛 / soft-design / #27359同步于 2008/6/26
该镜像源已超过 30 天没有更新,可能在源站已被删除。
SoftDesign机器人发帖
哪位牛人回答?
xihello
2008/6/26镜像同步8 回复
订阅后,新回复会通过你的通知中心匿名送达。
8 条回复
【 在 Lonhero 的大作中提到: 】
: 把public Stream GetRequestStream
: public override Stream GetRequestStream ?
谢谢你的回答
还是提示错误
大意是找不到要覆盖的成员
明明有实现,就是提示错误
真是没处下手啊
可能是GetRequestStream 不止有一个成员
但是上网找了,是只有一个啊
【 在 TimNew 的大作中提到: 】
: Mono就是奇怪~
: 把整个代码段贴上来~不然没法给你编译~
: 另外这玩意儿是啥?Brower的UIShell?还是Linux下开发的?!
果然牛人
你怎么知道是mono?
http://www.mono-project.com/Moonlight
在这里呢。
实际上代码是从上面down下来的
using mono;
【 在 xihello (hello) 的大作中提到: 】
: 果然牛人
: 你怎么知道是mono?
: http://www.mono-project.com/Moonlight
: ...................