Reputation: 1054
I'm trying to make an app that will send a POST request to https://owlexpress.kennesaw.edu/prodban/bwckschd.p_get_crse_unsec with some info and return a class list.
You can go here to go through the search "I'm using Fall 2015, MATH, Course 1190". https://owlexpress.kennesaw.edu/prodban/bwckschd.p_disp_dyn_sched
When I run the code below, it outputs what it returns to a string which goes into a webbrowser component. It shows:
Class Schedule Search
Fall Semester 2015
Mar 31, 2015
Stop You must select at least ONE subject .
I used Chrome Debugging to find the POST values and set them to what they are when I use the site normally. I even included some cookies in case it needed those.
EDIT:
Ok, new issue. I used a browser that works and got this: "term_in=201508&sel_subj=dummy&sel_day=dummy&sel_schd=dummy&sel_insm=dummy&sel_camp=dummy&sel_levl=dummy&sel_sess=dummy&sel_instr=dummy&sel_ptrm=dummy&sel_attr=dummy&sel_subj=MATH&sel_crse=1190&sel_title=&sel_insm=%25&sel_from_cred=&sel_to_cred=&sel_camp=%25&sel_levl=%25&sel_ptrm=%25&sel_instr=%25&begin_hh=0&begin_mi=0&begin_ap=a&end_hh=0&end_mi=0&end_ap=a"
I can't send that though because is uses some names twice, like sel_subj (and those are my key values in the dictionary)
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Net.Http;
using System.Net;
namespace ClassChecker
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
methods methods1 = new methods();
public MainWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
string temp = methods1.getData2();
Console.ReadLine();
webBrowser.NavigateToString(temp);
}
}
public class methods
{
public string getData2()
{
var cookieContainer = new CookieContainer();
using (var handler = new HttpClientHandler() { CookieContainer = cookieContainer })
using (var client = new HttpClient(handler))
{
client.BaseAddress = new Uri("https://owlexpress.kennesaw.edu");
var values = new Dictionary<string, string>
{
{ "sel_subj", "MATH" },
{ "term_in", "201508" },
{ "sel_day", "dummy"},
{ "sel_schd", "dummy"},
{ "sel_insm", "%"},
{ "sel_camp", "%"},
{ "sel_levl", "%"},
{ "sel_sess", "dummy"},
{ "sel_instr", "%"},
{ "sel_ptrm", "%"},
{ "sel_attr", "dummy"},
{ "sel_crse", "1190" },
{ "sel_title", "" },
{ "sel_from_cred", "" },
{ "sel_to_cred", "" },
{ "begin_hh", "0" },
{ "begin_mi", "0" },
{ "begin_ap", "a" },
{ "end_hh", "0" },
{ "end_mi", "0" },
{ "end_ap", "a" }
};
var content = new FormUrlEncodedContent(values);
cookieContainer.Add(client.BaseAddress, new Cookie("SESSID", "MFlIU0VSMTgxNjYx"));
cookieContainer.Add(client.BaseAddress, new Cookie("BIGipServerowlexpress-all", "2239289986.0.0000"));
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("text/html"));
var result = client.PostAsync("/prodban/bwckschd.p_get_crse_unsec", content).Result;
string resultContent = result.Content.ReadAsStringAsync().Result;
MessageBox.Show(result.Headers.ToString());
return resultContent;
}
}
}
}
Upvotes: 0
Views: 1016
Reputation: 5016
Per our discussion in comments, the service you are posting to requires a set of parameters with 'dummy' values AND another set of the same params with real values.
If you use NameValueCollection for the argument going into the FormUrlEncodedContent constructor, you will be able to use duplicate keys. It should then work
Upvotes: 2