1

I'm using this function to get the response of my requested URL. Not any error occurring with this function but the value it returns isn't what I want.

Here is the response from Firefox:

enter image description here

The function returns the HTML part but doesn't return the nextCursorEndpoint part. I want to get the nextCursorEndpoint part.

My code:

Private Function GET_Request(ByVal URL As String, ByVal CC As CookieContainer) As String
    Try
        Dim req As HttpWebRequest = DirectCast(WebRequest.Create(URL), HttpWebRequest)
        With req
            .Method = "GET"
            .CookieContainer = CC
            .UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0"
        End With

        Using response As WebResponse = req.GetResponse()
            Using resStream As Stream = response.GetResponseStream()
                Using streamReader As New StreamReader(resStream, Encoding.UTF8)
                    Return streamReader.ReadToEnd()
                End Using
            End Using
        End Using
    Catch ex As Exception
        InvokeIfRequired(ListBox2, DirectCast(Sub() ListBox2.Items.Add("[" & TimeString & "]:" & ex.Message), MethodInvoker))
        Return GET_Request(URL, CC)
    End Try
End Function
10
  • According to that screen shot, the value you're looking for was in fact returned by the server. What exactly isn't working? Commented Jan 20, 2016 at 14:34
  • The function I'm using doesn't return all the response , it just returns the html part without the nextCursorEndpoint which exactly i want. I added the function in my questions because i forgot it. Commented Jan 20, 2016 at 14:40
  • Can you show the contents of response and the result of GET_Request() as seen from the debugger? This code would return the entire response, so either something outside of this code isn't doing what you expect or the server isn't returning what you expect. (Also, you might want to re-think your Catch block. That's an infinite recursion waiting to happen.) Commented Jan 20, 2016 at 14:43
  • The response is too long to post it here. but inside the picture you can see two parts. The result I got from GET_Request() is the same as the second part which starts with <div class=" Timeline-item" role="row"> Commented Jan 20, 2016 at 14:46
  • It really sounds like you're going to have to do some debugging then. There's nothing in this code that is filtering (or even attempting to parse) JSON properties in that response. Commented Jan 20, 2016 at 14:49

1 Answer 1

2

[based on comments in the question above...]

The code in the question isn't doing any kind of filtering. So I strongly suspect that the server isn't returning what you expect it to. A very likely culprit for this could simply be the headers being sent in the request.

You're going to want to examine these closely during debugging. Firefox may simply be sending different headers than your code is sending, and the server-side logic for that resource may respond differently.

For example: If the Accept header is different and/or missing, than that could be signaling the server to provide different types of responses.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.