Force facebook re.scrape with asp.net

Hi,

I'm in need of re-scraping facebook information when a new page is loaded in my website. I've tried to create a web request to accomplish that.

 Protected Sub SendRequest(url As String)
        Dim fullurl As String = "https://graph.facebook.com/?id=" + url + "&scrape=true"
        Dim fullurl2 As String = "https://graph.facebook.com/?id=http://kanal10play.com/play?id=7c71c913-9552-435d-b5f4-905ed302afbf&scrape=true"

        '' Create a request using a URL that can receive a post. 
        Dim request As WebRequest = WebRequest.Create(fullurl)
        ' Set the Method property of the request to POST.
        request.Method = "POST"
        ' Create POST data and convert it to a byte array.
        Dim postData As String = "This is a test that posts this string to a Web server."
        Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData)
        ' Set the ContentType property of the WebRequest.
        request.ContentType = "application/x-www-form-urlencoded"
        ' Set the ContentLength property of the WebRequest.
        request.ContentLength = byteArray.Length
        ' Get the request stream.
        Dim dataStream As Stream = request.GetRequestStream()
        ' Write the data to the request stream.
        dataStream.Write(byteArray, 0, byteArray.Length)
        ' Close the Stream object.
        dataStream.Close()
        ' Response.Write(fullurl)
    End Sub

Open in new window


If I test the url as such in the browser it seems to work good, but when I use it with the above code on the page it seems that I can't get it to work. If anyone have any suggestions I'm grateful.

Thanks,

Peter
Peter NordbergIT ManagerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MlandaTCommented:
In your web browser, when you visit that URL, all it does it a GET. The browser receives the content from that call and displays it. The code you copied is doing a POST (calling the page and sending some data to it). These are two different operations.

All you need to do is to get the string downloaded from the page:
Public Function SendRequest(url As String) As String

    Dim fullurl As String = "https://graph.facebook.com/?id=" + url + "&scrape=true"

	Dim client As WebClient = New WebClient()
	Dim reply As String = client.DownloadString(fullurl)
	Return reply
	
End Function

Open in new window

Which you can call like this
Dim data As String = SendRequest("http://kanal10play.com/play?id=7c71c913-9552-435d-b5f4-905ed302afbf")
Debug.WriteLine(data)

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.