Excuse any ignorance on my part with this methodology as it is somewhat new to me. I’ve been reading up on it as much as I can, but haven’t been able to solve this yet.
I’m trying to accomplish a SSO with a vendor through an http post. Simple enough. I’ve done this in the past, but it usually returns a url that I can then redirect the user to. Unfortunately, with this vendor they are returning the entire page, html and all. Is this typical? If so, is my only solution to post this to a new window?
For reference, here’s my code so far:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(link);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
byte[] postBytes = Encoding.UTF8.GetBytes(postString);
request.ContentLength = postBytes.Length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(postBytes, 0, postBytes.Length);
requestStream.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
var responseStream = response.GetResponseStream();
var responseReader = new StreamReader(responseStream);
var responseString = responseReader.ReadToEnd();
responseReader.Close();
responseStream.Close();
response.Close();
Does everything look normal and ok so far?
It is normal for a POST request to return a new web page. I would think the redirect would be the abnormal case.
You’re pretty vague about your app, so I’m not sure how you’ll want to get the returned html shown to the user.
You might want to check out the WebClient class which could simplify your code considerably.