views:

238

answers:

1

Hi,

I've written the code to post the information to a page, however I don't know how to make the post target the iframe I've placed on the page. (I haven't tested this code so I'm not sure if the post even works)

    Dim param1, param2, result, url As String
    Dim request As HttpWebRequest
    Dim paramStream() As Byte
    Dim requestResponse As WebResponse

    param1= "name=" + Server.UrlEncode("My Name")
    param2= "email=" + Server.UrlEncode("[email protected]")
    paramStream = Encoding.ASCII.GetBytes(param1+ "&" + param2)
    url = "https://www.mysite.com/dosomething.php"

    request = WebRequest.Create(url)
    request.Method = "POST"
    request.ContentType = "application/x-www-form-urlencoded"
    request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.0; sv-SE; rv:1.9.1b2) Gecko/20081201 Firefox/3.1b2"
    request.ContentLength = paramStream.Length

    Using stream = request.GetRequestStream()
        stream.Write(paramStream, 0, paramStream.Length)
    End Using

    requestResponse = request.GetResponse()

    Using sr = New StreamReader(requestResponse.GetResponseStream())
        result = sr.ReadToEnd()
    End Using

That is what I have written to post to the website, however I would like the post to affect an iframe which I have placed on the page. I know when you're writing html you can have a target specified in the form tag

<form target="my_iframe" method="post" action="dosomething.php" />

But I wasn't sure if there is one similar to target that I can specify from VB code.

Just a note: I am trying to do a post from a ASP.NET page to a PHP page that is contained in an iframe.

I have not tested that this even works to post yet, if you see anything in my code that needs fixing up or have any suggestions for how to do this a different way please let me know.

Thanks,
Matt

A: 

When you're screen-scraping using HttpWebRequest, you're working at the HTTP layer, underneath the HTML layer that browsers are concerned about. HTTP does not know or care about frames or any other HTML elements layered on top. HTTP simply sends requests to URLs and gets responses back. So you simply need to send the POST request to the URL of the IFRAME. The fact that normally that URL lives in an IFrame shouldn't matter to your VB code.

Justin Grant