I'm creating a method that will go to our university catalog website and return the degree plan for the selected school year. This is my code to send a POST request to the dropdown box to select the school year.
// Post to catalog website to choose catalog year
HttpClient client = new HttpClient();
string catalogURL = "http://catalog.cpp.edu/index.php";
//Example choose 2015/16 catalog (value = "8")
//input parameter for drop down box in catalog
var parameter = new Dictionary<string,string>{ { "value", "8" } };
var encodedContent = new FormUrlEncodedContent(parameter);
var response = await client.PostAsync(catalogURL, encodedContent).ConfigureAwait(false);
if (response.StatusCode == HttpStatusCode.OK)
{
//get content:
var responseContent = await response.Content.ReadAsStringAsync ().ConfigureAwait (false);
//return html doc for catalog year
return responseContent;
}
However, I don't believe it's working. It's returning the html doc for the default page, the 2016/17 catalog, not the 2015/16 catalog. I think it may not be posting to the correct form, as there is another one before the drop down box: a search bar. What am I doing wrong?
This is what the source code looks like for the drop down box that I want to access:
<form name="select_catalog" method="post" action="/index.php" style="margin: 0px">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr valign="top">
<td>
<select tabindex="201" name="catalog" title="select a catalog" id="select_catalog">
<option value="10" selected> 2016-2017 University Catalog</option>
<option value="8"> 2015-2016 University Catalog</option>
<option value="9"> 2014-2015 University Catalog</option>
<option value="5"> 2013-2014 University Catalog</option>
<option value="4"> 2012-2013 University Catalog</option>
</select>
</td>
*Note: the url for the page remains the same regardless of the year selected, but the linke to the curriculum plans are different.
Sorry if this is a dumb question, but I don't have much experience with C# or .NET