0

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_c‌​amp=dummy&sel_levl=dummy&sel_sess=dummy&sel_instr=dummy&sel_ptrm=dummy&sel_attr=d‌​ummy&sel_subj=MATH&sel_crse=1190&sel_title=&sel_insm=%25&sel_from_cred=&sel_to_cr‌​ed=&sel_camp=%25&sel_levl=%25&sel_ptrm=%25&sel_instr=%25&begin_hh=0&begin_mi=0&be‌​gin_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;
        }

    }

}

}
Jrow
  • 1,026
  • 2
  • 12
  • 31
  • Have you been able to confirm (eg with Fiddler) that the form POST params are not going out correctly? The problem may just be that you have something wrong in the request content, not the code that is making the request... – Jim W Mar 31 '15 at 18:56
  • @JimW I found this in fiddler, so I guess it IS sending them "sel_subj=MATH&term_in=201508&sel_day=dummy&sel_schd=dummy&sel_insm=%25&sel_camp=%25&sel_levl=%25&sel_sess=dummy&sel_instr=%25&sel_ptrm=%25&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" – Jrow Mar 31 '15 at 19:05
  • 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). – Jrow Mar 31 '15 at 19:12
  • I doubt that those dummy values are even considered, they're probably ignored (since they are first). Have you tried using a HTML form of your own to get the request right? Eg. I started it for you http://jsfiddle.net/6fe2zxff/ just fill out the rest of the fields – Jim W Mar 31 '15 at 19:22
  • Bleh, I made this and it doesn't work here either: [http://jsfiddle.net/6fe2zxff/1/](http://jsfiddle.net/6fe2zxff/1/) – Jrow Mar 31 '15 at 19:53
  • I updated your jsfiddle, and added , the very thing I said it didn't need, and it did affect the outcome, reporting no matches, so maybe the other dummy vars are needed to. I guess they are expecting the dummy... – Jim W Mar 31 '15 at 20:25

1 Answers1

2

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

Jim W
  • 4,866
  • 1
  • 27
  • 43