I am accessing the REST web service from a VB application. I create an HttpWebResponse object and call GetRequestStream on it just fine, but when I call GetResponse, I get exception 401.
Here is my code (modified for publication):
Dim webRequest = DirectCast(WebRequest.Create(endpoint), HttpWebRequest)
webRequest.Method = "POST"
webRequest.ContentLength = contentLength
webRequest.ContentType = "application/x-www-form-urlencoded"
request.Credentials = New NetworkCredential(Username, Password)
' Works fine
Using stream As Stream = webRequest.GetRequestStream()
stream.Write(data, 0, data.Length)
End Using
' Barfs
Dim response As HttpWebResponse = DirectCast(webRequest.GetResponse(), HttpWebResponse)
I get exception 401 as soon as I call "webRequest.GetResponse ()". The response has a “WWW-Authenticate” header with a corresponding scope. I tried setting "webRequest.PreAuthenticate = True" and also manually setting the header using "webRequest.Headers.Add (HttpRequestHeader.Authorization, _authheader)"
I can’t track these requests using Fiddler / Wireshark, etc., because it is SSL traffic, I’m sure there is a way to control it, I have not found it yet.
,
- Connor