400 Bad Request with HTTP GET Request

Hi,

I am pretty new to web services as a whole and I'm trying to access and return data from a web service for a data project.

Everytime I send the Web Request I am receiving a 400 Bad Request message, now I am unsure if this is their end or mine. Is there any chance someone can look over this code and tell me if there is anything wrong out of the blue?

I was told to send the following headers in my request:

'Accept', 'Accept-Encoding','Authorization','Content-Length','Date'.

Now to my knowledge I have covered this in my code below yet I still receive a 400 Bad Request.

Dim _auth As String = String.Format("{0}:{1}", "user", "pass")
        Dim _enc As String = Convert.ToBase64String(Encoding.ASCII.GetBytes(_auth))
        Dim _cred As String = String.Format("{0} {1}", "Basic ", _enc)

        Dim getVars As String = "?type=Q&dln0=ABCDYAZ123&ind0=P&pc=BS23+1DE&"

        Dim WebReq As HttpWebRequest = DirectCast(WebRequest.Create(String.Format("https://myurl/this", getVars)), HttpWebRequest)

        'This time, our method is GET.
        WebReq.Method = "GET"
        WebReq.Accept = "application/json"
        WebReq.ContentLength = 0
        WebReq.AutomaticDecompression = DecompressionMethods.None
        WebReq.Headers(HttpRequestHeader.Authorization) = _cred
        WebReq.Date = Date.UtcNow

        'From here on, it's all the same as above.
        Dim WebResp As HttpWebResponse = DirectCast(WebReq.GetResponse(), HttpWebResponse)
        'Let's show some information about the response
        Console.WriteLine(WebResp.StatusCode)
        Console.WriteLine(WebResp.Server)

        'Now, we read the response (the string), and output it.
        Dim Answer As Stream = WebResp.GetResponseStream()
        Dim _Answer As New StreamReader(Answer)
        Console.WriteLine(_Answer.ReadToEnd())

Open in new window


Please can someone point me in the right direction into my failure as I'm struggling to see what is wrong.

Regards,

James
Lynchie435Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Shalom CarmelCTOCommented:
Send your request to this address, copy the results and paste back here.
echo.httpkit.com

This echo service will capture your request and headers and throw it back at you as a response.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
giltjrCommented:
The server's log should give you more information.  If you don't have access to the log, then I would suggest you get hold of somebody that does.
Lynchie435Author Commented:
That helped me out mate, Muchos!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTTP Protocol

From novice to tech pro — start learning today.