How to register my own protocol using the WebBrowser control?

In a WP7 Silverlight application with a WebBrowser control, I want to use my own protocol, such as "myttp: //", to deliver some local content. I cannot use Navigate () for IsolatedStrorage because some content will be created on demand. For the same reason, NavigateToString () is also not suitable for me.

I tried registering WebRequestCreator output for my MYTP protocol

myCreator = new MyRequestCreator(); 
WebRequest.RegisterPrefix("mytp://", myCreator);

but it is not called from the browser control if I go to "mytp: //test.html". If I create a WebRequest through code

WebRequest request;
request = WebRequest.Create("mytp://test.html");`

everything works perfectly.

Any suggestions what is wrong or how to do it?

+3
2

WebBrowser HTTP Internet Explorer Windows Phone -. HTTP- HTTP- , . , .

+3

AnthonyWJones, , "HTTP- ".

Silverlight " " ( ..) System.Net.Browser.WebRequestCreator.BrowserHttp httprequest factory ( "normal/aside" System.Net.Browser.WebRequestCreator.ClientHttp factory) WP7. SDK, , , , , cookie . , , .

, factory / cookie/userauth , WebBrowser, , ClientHttp factory, ( , 7.0 7.1 ), - . - factory (WP7 v. Mango 7.1):

A first chance exception of type 'System.Net.ProtocolViolationException' occurred in System.Windows.dll
at System.Net.Browser.BrowserHttpWebRequest.InternalBeginGetRequestStream(AsyncCallback callback, Object state)
at System.Net.Browser.AsyncHelper.BeginOnUI(BeginMethod beginMethod, AsyncCallback callback, Object state)
at System.Net.Browser.BrowserHttpWebRequest.BeginGetRequestStream(AsyncCallback callback, Object state)
at MyApp.MyPage..ctor()

MyPage:

public class WRC : IWebRequestCreate { public WebRequest Create(Uri uri) { return null;/*BREAKPOINT1*/ } }

WebRequest.RegisterPrefix("js://", new WRC()); // register the above handler

brwHttp = (IWebRequestCreate)typeof(System.Net.Browser.WebRequestCreator).GetProperty("BrowserHttp").GetValue(null, null);
var tmp = brwHttp.Create(new Uri("js://blah.blah.blah"));

var yyy = tmp.BeginGetResponse(callback, "wtf");
var response = tmp.EndGetResponse(yyy); /*BREAKPOINT2*/

var zzz = tmp.BeginGetRequestStream(callback, "wtf"); /*<---EXCEPTION*/
var stream = tmp.EndGetRequestStream(zzz); /*BREAKPOINT3*/

:

  • breakpoint1
  • breakpoint2 , "" NULL
  • breakpoint3 - ,

, Silverlight Browser , / ProtocolViolation. , WP7 (7.0, 7.1) http, "js://" BrowserHttpWebRequest.InternalBeginGetRequestStream, stacktrace:)

, - Silverlight Browser Stack API.

, WebBrowser factory. , factory BrowserHttp, , webbrowser, , , , WebBrowser factory , , , - . , BrowserHttp factory ( , ) 6 - , , ! ( , )

+3

Source: https://habr.com/ru/post/1785376/


All Articles