Accessing SOS with Basic Authentication - .Net (IronPython) 1
This example is provided by Kari Hoijarvi from WUSTL.
Download IronPython from http://www.codeplex.com/Wiki/View.aspx?ProjectName=IronPython
Save the following code into a file called sos2.py
to run the code:
ipy
>>>import sos2
>>>sos2.test()
The sos2.py file:
import clr;
import System
clr.AddReferenceByPartialName("System.Data")
clr.AddReferenceByPartialName("System.Web")
clr.AddReferenceByPartialName("System.Xml")
from System import *
from System.IO import *
from System.Net import *
from System.Net.Sockets import *
from System.Text import *
from System.Xml import *
def test():
query = Encoding.UTF8.GetBytes(
"""<?xml version="1.0" encoding="UTF-8"?>
<GetObservation xmlns="http://www.opengeospatial.net/sos"
xmlns:gml="http://www.opengis.net/gml"
xmlns:ogc="http://www.opengis.net/ogc"
xmlns:ows="http://www.opengeospatial.net/ows"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opengeospatial.net/sos
http://mars.uni-muenster.de/swerep/trunk/sos/0.0.31/sosGetObservation.xsd"
service="SOS" version="0.0.31">
<offering>EO1H0410342004085110PY</offering>
<observedProperty>urn:ogc:def:phenomenon:OGC:1.0.30:hyperion_B021</observedProperty>
<observedProperty>urn:ogc:def:phenomenon:OGC:1.0.30:hyperion_B051</observedProperty>
<resultFormat>application/zip</resultFormat>
</GetObservation>
""")
req = HttpWebRequest.Create("http://test.geobliki.com/sos")
req.Method = "POST"
req.Credentials = NetworkCredential("some", "user")
req.ContentType = "text/xml; charset=\"UTF-8\"";
req.ContentLength = query.Length
req.UserAgent = "IronPython"
reqstm = req.GetRequestStream()
reqstm.Write(query, 0, query.Length);
rsp = req.GetResponse();
try:
print "============ begin headers =================="
for h in rsp.Headers:
print h + ": " + rsp.Headers[h]
print "============ end headers =================="
print "============ begin response =================="
print ""
print StreamReader(rsp.GetResponseStream()).ReadToEnd()
print ""
print "============ end of response =================="
finally:
print "closing response"
rsp.Close()
's Blog