dcsimg
Results 1 to 7 of 7

Thread: [ RESOLVED]Host on Web page

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2015
    Location
    USA, New Jersey
    Posts
    23

    Resolved [ RESOLVED]Host on Web page

    Hi, I'm learning and don't know yet how to solve this problem. This is also my first post .

    I want to use 2 urls for download quotes 1 for historical and another for quotes. The urls are http://download.finance.yahoo.com and http:// ichart.yahoo.com , I have the folowing code, works fine using one HOST: but i need use both hosts.
    Thanks for any Help
    Tony

    -------------------------------------------------------------------------------------------------------
    Function UrlMsg$(ByVal tUrl$) ' pretend to be a browser
    tDocument$ = URLDocument(tUrl$)

    Msg$ = "Request Method: GET" & vbCrLf
    Msg$ = ""
    Msg$ = Msg$ + "GET /" & tDocument$ & " HTTP/1.1" & vbCrLf
    Msg$ = Msg$ + "Host: ichart.yahoo.com" & vbCrLf
    Msg$ = Msg$ + "Host: download.finance.yahoo.com" & vbCrLf

    Msg$ = Msg$ + "User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:12.0) Gecko/20100101 Firefox/12.0" & vbCrLf
    Msg$ = Msg$ + "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" & vbCrLf
    Msg$ = Msg$ + "Accept-Language: en-us,en;q=0.5" & vbCrLf
    'Msg$ = Msg$ + "Accept-Encoding: gzip, deflate" & vbCrLf

    'Msg$ = Msg$ + "Connection: keep-alive" & vbCrLf

    Msg$ = Msg$ + "Connection: Close" & vbCrLf
    Msg$ = Msg$ & vbCrLf
    UrlMsg$ = Msg$

    End Function
    ------------------------------------------------------------------------------------
    Last edited by Tony.; Feb 22nd, 2015 at 12:33 AM. Reason: Resolved

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,687

    Re: Host on Web page

    You can't connect to more than one host in a single connection... you'll need to make two passes... first to one url, the second to the other.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Feb 2015
    Location
    USA, New Jersey
    Posts
    23

    Re: Host on Web page

    Thank you for your reply
    I'm trying using if
    Function UrlMsg$(ByVal tUrl$) ' pretend to be a browser
    tDocument$ = URLDocument(tUrl$)

    If InStr(tDocument$, "ichart") Then
    Requesturl :
    Else


    Is any way to use the if?


    Tony.
    Last edited by Tony.; Feb 22nd, 2015 at 11:03 AM. Reason: Update

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    24,726

    Re: Host on Web page

    as suggested by techgnome
    call the function twice, once for each url
    combine the messages in the calling procedure
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Feb 2015
    Location
    USA, New Jersey
    Posts
    23

    Re: Host on Web page

    Thanks for the suggestion, some time ago yahoo requests needs the host and that's when the problem start this is a program not created by me and I'm trying to fix, i'm learning at the same time but i don't know to much yet, easy things still a big step for me.
    There is also a function for the host should stripe the host from the urls , like the following but also don't work.

    Function URLHost(ByVal tUrl$) As String
    tUrl$ = Trim(tUrl$)
    tUrl$ = URLstripHttP(tUrl$)
    For A = 1 To Len(tUrl$)
    If Mid$(tUrl$, A, 1) = "/" Then
    URLHost$ = Left$(tUrl$, A - 1)
    Exit Function
    End If
    Next
    URLHost$ = tUrl$: Exit Function 'Not Found
    End Function

    I'm keep trying
    Thanks.

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    24,726

    Re: Host on Web page

    you can try like
    change the function to
    Code:
    Function UrlMsg$(ByVal tUrl$, myhost) ' pretend to be a browser
    
    'change this line to
    'Msg$ = Msg$ + "Host: ichart.yahoo.com" & vbCrLf
    Msg$ = Msg$ & myhost & vbnewline
    change the call of the function to include the required host string like
    Code:
    result = urlmsg$("http://download.finance.yahoo.com", "Host: download.finance.yahoo.com")
    change both the url and host for the call to ichart
    note:- + should not be used to concatenate strings

    but also don't work.
    in what way? error? wrong result? nothing happen?
    i notice, you have 2 functions, urlstipphttp, which is called from within the urldocument function, removes the "http://" as the urldocument function then does not find any "/" (already removed) it returns a, not found result, empty string, but i am unsure if the document url passed to the function should or could have / after the host, in which case the 2 functions may then work correctly,
    if returning an empty string is correct if no / is found then the user should be notified so he can supply a correct url, and the function should exit, rather than trying to GET an invalid (empty string) document

    but also note there are typing errors in then urldocument1 function, that will cause it to fail if it is ever used, OPTION EXPLICIT and dimensioning of all variables, would pinpoint all those errors before it can run

    the urlhost function, posted above, is also never called as far as i can tell from the information i have
    you could call the urlhost function like
    Code:
    msg$ = msg$ & "GET /" & tDocument$ & " HTTP/1.1" & vbCrLf
    msg$ = msg$ & "Host:" & URLHost(tUrl$) & vbNewLine
    this could save the changing of the function to have a 2nd parameter
    apart from the last line both urldocument and urlhost function appear to be the same, which as stated before may be a problem with urldocument function
    using a loop of all characters in either of those functions, appears to be poor programming when instr would do better, like
    Code:
    Function URLHost(ByVal tUrl$) As String
    tUrl$ = Trim(tUrl$)
    tUrl$ = URLstripHttP(tUrl$)
    pos = instr(turl$, "/")
    if pos = 0 then
    URLHost$ = tUrl$
    else
    URLHost$ = Left(tUrl$, pos - 1)
    end if
    End Function
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Feb 2015
    Location
    USA, New Jersey
    Posts
    23

    Resolved Re: Host on Web page

    Westconn1, I used the two last sugestions the url function call and the tFunction URLHost, changed the vbNewLine to vbCrlf and bingo, works fine,
    thank you very much for your help and also thanks to techgnome .

    Tony.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width