Post Stream

P

Peter Lapic

The following function returns a stream in text as a result of a URL I pass.
The problem I have is if a URL returns a client side post (see example
below) I want to be able to pass this stream back and have returned another
stream which is the result of that post.
I am just not sure how to handle this type of posting.

Regards
Peter Lapic

Function StreamHTMLContent(ByVal xURL As String)

Dim oStream As Stream

Dim oURLRequest As HttpWebRequest

Dim oURLResponse As HttpWebResponse

Try

oURLRequest = WebRequest.Create(xURL)

oURLResponse = oURLRequest.GetResponse()

oStream = oURLResponse.GetResponseStream()

Return New StreamReader(oStream).ReadToEnd()

Catch oException As Exception

Return oException.Message

End Try

End Function

==============================================================

<html>
<head>
<title>Sample</title>
</head>

<body>

<script language="JavaScript">
function submitForm(){
document.content.submit();
}
</script>


<form name="content" action=http://www.test.com.au/test.asp method="POST"">
11
<input type="hidden" name="Sa_waybill_list" value="5916803486">
<i>Please wait, getting POD information for <B>"5916803486"</b></i>
<BR><BR><BR>
<input type="hidden" name="retainwaybills" value="true">
<input type="hidden" name="Sa_database" value="ACTIVE">
<input type="hidden" name="Sa_screen" value="trakmain">
<input type="hidden" name="Sa_language" value="E">
<input type="hidden" name="SaFormName"
value="SeeMyShipments__Ftrakmain_htm">
<input type="hidden" name="Sa_waybill_ref_radio" value="waybill">
<input type="hidden" name="Sa_waybill_piece_nbr" value="5916803486">
<input type="hidden" name="Sa_current_waybill_nbr" value="5916803486">
<input type="hidden" name="Sa_IPEC" value="1">
<input type="hidden" name="Sa_account_nbr" value="ADMIN">
<BR>

<input type="hidden" name="B1" value="Proof of Delivery">

<script language="JavaScript">
document.content.submit();
</script>

</form>

</body>
</html>
 
M

[MSFT]

Hi Peter,

Thank you for using the community. Regarding the issue, I will find proper
resource to assist you and update you as soon as possible.

Regards,

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
B

bruce barker

this is pretty trival. set the content-type to
"application/x-www-form-urlencoded", and pass the post data as

<fieldname>=<value>&<fieldname=<value>....

be sure to url encode the values. if this seems too difficult, use the
UploadValues method of the webclient class.

-- bruce (sqlwork.com)
 
P

Peter Lapic

I have tried your suggestion with new function (see below) but I still get
the first page instead of the second.
What am I doing wrong?

Regards
Peter
Function PostStreamHTMLContent(ByVal xURL As String)

Dim oStream As Stream

Dim oWriter As StreamWriter

Dim oURLRequest As HttpWebRequest

Dim oURLResponse As HttpWebResponse

Dim xPost As String

Try

xPost=
"Sa_waybill_list=5916803486&retainwaybills=true&Sa_database=ACTIVE&Sa_screen
=trakmain&Sa_language=E&SaFormName=SeeMyShipments__Ftrakmain_htm&Sa_waybill_
ref_radio=waybill&Sa_waybill_piece_nbr=5916803486&Sa_current_waybill_nbr=591
6803486&Sa_IPEC=1&Sa_account_nbr=ADMIN&B1=Proof of Delivery"

oURLRequest = WebRequest.Create(xURL)

oURLRequest.Method = "POST"

oURLRequest.ContentLength = xPost.Length

oURLRequest.ContentType = "application/x-www-form-urlencoded"

Try

oWriter = New StreamWriter(oURLRequest.GetRequestStream())

oWriter.Write(xPost)

Catch e As Exception

Return e.Message

Finally

oWriter.Close()

End Try

oURLResponse = oURLRequest.GetResponse()

oStream = oURLResponse.GetResponseStream()

Return New StreamReader(oStream).ReadToEnd()

Catch oException As Exception

Return oException.Message

End Try

End Function
 

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

Top