Jump to content

winhttp.winhttprequest set referrer example


Recommended Posts

I'm trying to set a referrer, but it's not visible in the header, ideas?

 

$oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
Local $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
$oHTTP.Open("POST", "https://example.com", False)
$oHTTP.SetRequestHeader("Accept", "*/*")
$oHTTP.SetRequestHeader("Referrer", 'http://www.123.com')
$oHTTP.Send("")
$oHTTP.WaitForResponse

$oReceived = $oHTTP.ResponseText
$oStatusCode = $oHTTP.Status
$oHeader = $oHTTP.GetAllResponseHeaders()

MsgBox(0,"",$oHeader) ; Referrer is not working

Func MyErrFunc()
    MsgBox(0, "AutoItCOM Test", "We intercepted a COM Error !" & @CRLF & @CRLF & _
            "err.description is: " & @TAB & $oMyError.description & @CRLF & _
            "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _
            "err.number is: " & @TAB & Hex($oMyError.number, 8) & @CRLF & _
            "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _
            "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _
            "err.source is: " & @TAB & $oMyError.source & @CRLF & _
            "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _
            "err.helpcontext is: " & @TAB & $oMyError.helpcontext _
            )
EndFunc   ;==>MyErrFunc

 

Link to comment
Share on other sites

1 hour ago, beginner10 said:

it's not visible in the header

You're right, it's not visible in the response headers.  That's because it does not exist in the response headers.  Referrer is a request header.  Request headers describe the request and response headers describe the response.  So why would you expect to see that request header ("Referrer") returned by a method named GetAllResponseHeaders? :)  There's not a GetAllRequestHeaders method because you are the one building and sending the request so you know what request headers are being sent.  Of course, this assumes that your request was successful. 😉

 

Edited by TheXman
Link to comment
Share on other sites

@TheXman

Thanks for the reply.

The truth is, I haven't used Winhttp in the past.
I understand what you're saying, so referres is a request header, using SetRequestHeader. But is there any way to see if that header was actually set correctly?
I would have expected that after sending it with SetRequestHeader(), I could see it with GetAllResponseHeaders(). But I understand why it doesn't work that way.

 

Thanks

Link to comment
Share on other sites

3 minutes ago, beginner10 said:

But is there any way to see if that header was actually set correctly?

There are numerous ways.  One very easy way to see your request, is to send your request to the Postman echo api. (https://postman-echo.com/get).  It will show you your request in a JSON response.

Link to comment
Share on other sites

  • Moderators

beginner10,

And a third attempt (plus one with another account) - do you think we are stupid? Take a month off to think whether you are going to remain a member of this forum - because the next infraction will take the decision out of your hands.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...