問題描述
VB.NET ‑ WebBrowser 附加標題 ‑ 用戶代理覆蓋/取消其他標題? (VB.NET ‑ WebBrowser Additional Headers ‑ User Agent Overrides / Cancels Other Headers?)
I am trying to add 2 things into a WebBrowser control request: 1) User Agent, 2) Referring URL, (Optional 3): Accept Type.
My Code:
Dim Headers As String = "Accept: */*" & Chr(10) & Chr(13)
Headers = Headers & "Referer: " & "http://www.google.com/" & Chr(10) & Chr(13)
Headers = Headers & "User‑Agent: " & "My Program User Agent" & Chr(10) & Chr(13)
WebBrowser1.Navigate(UrlToVisit, "_self", Nothing, Headers)
The above code ONLY sends the user agent. If I remove the user agent then the Accept & The referring URL are both set.
It seems that whenever I add in the user agent additional header any other custom additional headers are being cancelled out.
Is this a bug with WebBrowser / something that is not possible to do or am I doing something seriously wrong here!?!
‑‑‑‑‑
參考解法
方法 1:
EDIT: Worked out the issue moments afterwards ‑ My Useragent which was coming from a textbox had an additional vbcrlf causing the other headers not to work, after trimming this all working ok :)
方法 2:
Another note: you set chr(10) & chr(13) when it should be the other way round. CRLF as in the http standard means chr(13) & chr(10)