Link to home
Start Free TrialLog in
Avatar of jsbx
jsbxFlag for Chile

asked on

Grab data from remote page

Hello,

I'm using HTTPWebRequest to grab data from this remote page:
http://www.interchile.com/empty_page.asp that is absolutly empty with just the word Hello *as you can see if you connect directly to it and view source*.

<WebMethod()> _
    Public Function GENERADOR(ByVal StringPrimario As String)

        Dim uri As New Uri("http://think/magic/SpGetPost.asp")
        Dim data As String = "Texto_Plano=" & StringPrimario & "&go=si"
        If (uri.Scheme = uri.UriSchemeHttp) Then

            Dim request As HttpWebRequest = HttpWebRequest.Create(uri)
            request.Method = WebRequestMethods.Http.Post
            request.ContentLength = data.Length
            request.ContentType = "application/x-www-form-urlencoded"

            Dim writer As New StreamWriter(request.GetRequestStream())
            writer.Write(data)
            writer.Close()

            Dim response As HttpWebResponse = request.GetResponse()
            Dim reader As New StreamReader(response.GetResponseStream())
            Dim tmp As String = reader.ReadToEnd()
            response.Close()

            Return tmp '<- here

        End If
    End Function





Something in this code modify the data so I grab all this XML code instead of just the data "hello":


<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GENERADORResponse xmlns="http://dtebank.cl/"><GENERADORResult xsi:type="xsd:string">Hello</GENERADORResult></GENERADORResponse></soap:Body></soap:Envelope>

What I need is that "tmp" (look at the code) returns just the value: hello

Thank You.

band
Avatar of Snarf0001
Snarf0001
Flag of Canada image

The interchile url isn't actually in your code.
Can you explain the relationship between these urls:

http://www.interchile.com/empty_page.asp
http://think/magic/SpGetPost.asp

Which one has the blank source, where "think" is getting called from, which one has the function in the provided source?

Depending on how you're calling it, could be the "WebMethod" declaration, this is usually used from inside an aspx to mark a function as callable from javascript, which often wraps it in a SOAP response as you've shown.

But need more info.
Avatar of jsbx

ASKER

It is, i pasted and old code, sorry:
think is my laptop.

    <WebMethod()> _
    Public Function GENERADOR(ByVal StringPrimario As String)

        Dim uri As New Uri("http://www.interchile.com/empty_page.asp")
        Dim data As String = "Texto_Plano=" & StringPrimario & "&go=si"
        If (uri.Scheme = uri.UriSchemeHttp) Then

            Dim request As HttpWebRequest = HttpWebRequest.Create(uri)
            request.Method = WebRequestMethods.Http.Post
            request.ContentLength = data.Length
            request.ContentType = "application/x-www-form-urlencoded"

            Dim writer As New StreamWriter(request.GetRequestStream())
            writer.Write(data)
            writer.Close()


            Dim response As HttpWebResponse = request.GetResponse()
            Dim reader As New StreamReader(response.GetResponseStream())
            Dim tmp As String = reader.ReadToEnd()
            response.Close()

            Return tmp

        End If
    End Function
Hi,

Code you written to get work 'Hello' is correct. Variable tmp has value 'Hello' on last line at return statement.

You have addedWebMethod() attribute for this method. Assuming that, you are calling GENERADOR method through ajax. Soap Envelop related code is added due to that.

Regards,
Rajul
Avatar of jsbx

ASKER

I'm using <WebMethod()> _ since this is a webservce
ASKER CERTIFIED SOLUTION
Avatar of Snarf0001
Snarf0001
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jsbx

ASKER

So how to get rid of all the soap evnelope? this is a public webservce, i can't delete <WebMethod()>  is there a native parser or something?
Avatar of jsbx

ASKER

Snarf0001:

I can't (or don't know how) since it is a webservce it won't show on the browser if I omit <WebMethod()>
I'm not a .net developer so i'm totaly lost
Avatar of jsbx

ASKER

Update: The data is arriving Ok to the VB

It changes in the after Return tmp
Avatar of jsbx

ASKER

Thank you
Great, sorry for the delay, had to step into meetings.
Glad you got it working.