I have some simple VB.Net code and I am trying to get a remote web page. When I use this code to get for example msn.com the code performs flawlessly all of the time. When I try to use this code to access amazon.com the code and on every other request performs flawlessly. But every other request especially if there is some wait time, the code renders the as this:
��Yms�8���_!��` Ӓwwj�4�r�f2�$�3{U����o&@Ɏ��~�I�N���(�� ��4��o�f���~�����ty2��Eg"��G������ȟ_�w&r�C���N�(4���������_b���L*���J=?�P��j=����^�}�[n����7� AND MORE CHARACTERS JUST LIKE THIS.
It might be a timeout issue, it might be a page encoding issue with the response. I can't figure it out.
Here is the code: ( and saved on my localhost as test.aspx )
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.IO" %>
<script language="VB" runat="server">
Sub Page_Load(Sender as Object, E as EventArgs)
Dim q As String
Randomize
q= (Rnd)
Dim oRequest As WebRequest = WebRequest.Create("https://www.amazon.com/dp/0132350882/?" & q)
Dim oResponse As WebResponse = oRequest.GetResponse()
Dim oStream As Stream = oResponse.GetResponseStream()
Dim oStreamReader As New StreamReader(oStream, Encoding.UTF8)
Response.Write(oStreamReader.ReadToEnd())
oResponse.Close()
oStreamReader.Close()
End Sub
</script>
Also if I load the page, the first time the encoding is wrong but if I quickly reload the page a second time the encoding is correct. If I keep reloading the page after that, and very quickly I might add, it is always correct.
Thanks in advance,
Jim
OK I modified the code above to become( and it did nothing to fix the issue ):
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.IO" %>
<script language="VB" runat="server">
Sub Page_Load(Sender as Object, E as EventArgs)
Dim q As String
Randomize
q= (Rnd)
Dim oRequest As WebRequest = WebRequest.Create("https://www.amazon.com/dp/0132350882/?" & q)
Dim oResponse As WebResponse = oRequest.GetResponse()
Dim oStream As Stream = oResponse.GetResponseStream()
Dim oStreamReader As New StreamReader(oStream, Encoding.UTF8)
Response.Write(oStreamReader.ReadToEnd())
oResponse.Close()
oStreamReader.Close()
End Sub
</script>
</body>
</html>
But it is very strange when the remote renders correctly in the browser everything inside the is still there. However even with the updated code when it displays the wrong character set the is stripped out of the head of the document. I wonder if Amazon is doing this?
I am trying to say now and then the content inside the HEAD is being stripped out