HTTP Handlers

E

Ertan Sekmen

hi there,
I do not know if this is the correct form to post this but I would kindly
ask any help on creating a class to submit a Form.

We have a webservice that accepts web forms. when we create a form with a
textarea called data, (the value is an XMLDocument) then submit this form
via action=https://blabla... it works fine. But I would like to implement
this operation in our business layer, which is a class.

I started with creating httpwebrequest object. but "result" string is always
empty. I try this another web page, it works great.

I think that the blabla server process only web forms, something like
request.form("data"). How can I add form values to httprequest? I search
through msdn and I Found that there are two objects : System.Web.HttpRequest
and System.Net.HttpWebRequest. I cannot get System.Web.HttpRequest object
working. when I try to add a value & key pair to
System.Web.HttpRequest.forms collection it raises an error : "forms
collection is read only".

Thanks in advance,
Ertan



'-- code begins here
Dim oRequest As HttpWebRequest = WebRequest.Create("https://blabla")

Dim myWriter As StreamWriter
Dim encoding As New ASCIIEncoding
Dim postData As String


Dim result As String
Dim xmlFile As String = New StreamReader("c:\xmldoc.xml").ReadToEnd
postData = "DATA=" & xmlFile
Dim data As Byte() = encoding.GetBytes(postData)
oRequest.Form.Set("DATA", postData)
oRequest.Method = "POST"
oRequest.ContentLength = data.Length
oRequest.ContentType = "application/x-www-form-urlencodedl"
oRequest.KeepAlive = True
Dim newStream As Stream = oRequest.GetRequestStream()
Try
newStream.Write(Data, 0, Data.Length)
Catch ex As Exception
Response.Write(ex.Message)
Finally
newStream.Close()
End Try


Dim oResponse As HttpWebResponse = oRequest.GetResponse()
Dim sr As StreamReader = New
StreamReader(oResponse.GetResponseStream())
result = sr.ReadToEnd
sr.Close()
Response.Write(result)
'--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top