BrowserHttpWebRequest

From IronPython Cookbook

This code is one of the examples from the IronPython Web IDE, which is a great way of experimenting with IronPython code live in the browser.

The BrowserHttpWebRequest gives you access to server side resources including headers and making posts.

from System import Uri, UriKind
from System.Windows.Browser.Net import BrowserHttpWebRequest
from System.IO import StreamReader

#help(BrowserHttpWebRequest)

uri = Uri('/', UriKind.Relative)
request = BrowserHttpWebRequest(uri)

request.Method = 'GET'

response = request.GetResponse()
stream = StreamReader(response.GetResponseStream())
print stream.ReadToEnd()
stream.Close()

for item in response.Headers.Headers:
    print item, ':', response.Headers[item]


Back to Contents.

TOOLBOX
LANGUAGES