visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
315 experts, 1193 registered users, 1659 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


05/10/2011 1h30 : Steve Jobs is dead, the father of Apple ][ is gone, we are all orphaned.

Languages :: ASP :: VBS :: how to use SetRequestHeader and WinHttpRequest ?


By: FiatLink Belgium  Date: 08/09/2005 10:30:27  English  Points: 20 Status: Answered
Quality : Excellent
I'm trying to use the methods SetRequestHeader WinHttpRequest in visual basic and can't figure how...
By: VGR Date: 08/09/2005 10:42:15 English  Type : Answer
Hi.

You may use this kind of code :

Function GetData(strUrl) Dim web Const WinHttpRequestOption_EnableRedirects = 6 Set web = Nothing On Error Resume Next Set web = CreateObject("WinHttp.WinHttpRequest.5.1") If web Is Nothing Then Set web = CreateObject("WinHttp.WinHttpRequest") If web Is Nothing Then Set web = CreateObject("MSXML2.ServerXMLHTTP") If web Is Nothing Then Set web = CreateObject("Microsoft.XMLHTTP") web.Option(WinHttpRequestOption_EnableRedirects) = True web.Open "GET", strURL, False web.SetRequestHeader "REFERER", strUrl web.SetRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)" web.SetRequestHeader "Accept", "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5" web.SetRequestHeader "Accept-Language", "en-us,en;q=0.5" web.SetRequestHeader "Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7" web.Send If web.Status = "200" Then GetData = web.ResponseText Else GetData = "" End If End Function



or, using proxy settings (from this old topic :

Function GlobalScreenScrapex(strURL, strMarkup) '*************************************************************************** ***** 'Screen Scrape the Data '*************************************************************************** ***** dim objWinHttp Dim strHTML dim m_cPostBuffer 'const MARKUP_FRAMES = "1" 'const MARKUP_AS_IS = "" on error resume next 'call AddPostKey("data", "tehdatatosend") Set objWinHttp = CreateObject("WinHttp.WinHttpRequest.5") objWinHttp.Open "POST", strURL objWinHttp.SetProxy 2, "proxy1:8080" objWinHttp.SetCredentials "gooddomain\userid", "goodpassword", 1 objWinHttp.SetRequestHeader "CONTENT-TYPE", "application/x-www-form-urlencoded" objWinHttp.SetTimeouts 30000, 30000, 30000, 30000 objWinHttp.Send m_cPostBuffer if Err.number <> 0 then strHTML = "There is a problem in reaching the Remote host. Please try again later, or contact the Content Manager if the problem persists. Error: " & Err.number & " " & Err.description & strURL & " " strHTML = strHTML & "Status: " & objWinHttp.Status & " " & objWinHttp.StatusText ' Get the text of the response. else strHTML = objWinHttp.ResponseText end if Set objWinHttp = Nothing 'return the html to the calling program GlobalScreenScrapex = strHtml end Function



You also have C++ example code directly on the MSDN help page

regards

Do register to be able to answer

EContact
browser fav
page generated in 330.753800 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page