I am trying to login into REST API from vb.net.
Dim pageSource As String Dim formUrl As String = "http://10.23.202.18:8080/usermgmt-0.1.0.BUILD-SNAPSHOT/resources/j_spring_security_check"' NOTE: This is the URL the form POSTs to, not the URL of the form (you can find this in the "action" attribute of the HTML's form tag Dim formParams As String = String.Format("j_username={0}&j_password={1}", "administrator", "admin") Dim cookieHeader As String Dim req As WebRequest = WebRequest.Create(formUrl) req.ContentType = "application/x-www-form-urlencoded" req.Method = "POST" Dim bytes As Byte() = Encoding.ASCII.GetBytes(formParams) req.ContentLength = bytes.Length Using os As Stream = req.GetRequestStream() os.Write(bytes, 0, bytes.Length) End Using Dim resp As WebResponse = req.GetResponse() cookieHeader = resp.Headers("Set-cookie") Using sr As New StreamReader(resp.GetResponseStream()) pageSource = sr.ReadToEnd() End Using
But in response I am getting resp.Headers("Set-cookie"),resp.Headers("Location")
as empty and in response URLgetting like:
You have tried to access a protected area of this application. By default you can login as "admin", with a password of "admin"
So please help me to come out from this.