Okay, so I have a question; I am doing a get, scraping out the event validation and viewstate to send back, but when I try to post back to the page, I am getting what appears to be a non-posted page on the other end. Since I can't seem to reuse the original request, the page I get has different viewstate information, so I'm not getting the post I hoped (I think that is what is happening anyway). I am definitely hitting the page; I am doing a Response.Write for the returned content and it is definitely loading the correct page in the background. I seem to be back at square one (albeit using the baked-in features of 4.5, which is nice :)). So I am definitely calling the right page, but it does not appear to actually post. Here is the code I am using:
//First call to get the hidden fields from the page
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(@"http://localhost:51749/Default.aspx");
request.Method = "GET";
request.ContentType = "application/x-www-form-urlencoded";
HttpWebResponse resp = (HttpWebResponse)request.GetResponse();
string respString = string.Empty;
using (Stream strm = resp.GetResponseStream())
{
using (StreamReader sr = new StreamReader(strm))
{
respString = sr.ReadToEnd();
}
}
request = (HttpWebRequest)HttpWebRequest.Create(@"http://localhost:51749/Default.aspx");
List controls = respString.Split('\\n').Select(o => o.Replace("\\r", string.Empty).Trim()).Where(o => o.StartsWith("<input") && o.IndexOf("hidden") > -1).ToList();
request.Method = "POST";
request.ContentType = "multipart/form-data";
//copied from StackOverflow and updated to hit my URL
using (HttpClient client = new HttpClient())
{
using (MultipartFormDataContent content = new MultipartFormDataContent())
{
var values = new\[\]
{
new KeyValuePair("txtFile", "BALHHHHH"),
new KeyValuePair("fu1", fileName),
}.ToList();
foreach (string cont in controls)
{
List attributes = cont.Split(' ').Whe