C# HttpClient not sending POST variables -
i'm trying make app send post request https://owlexpress.kennesaw.edu/prodban/bwckschd.p_get_crse_unsec info , return class list.
you can go here go through search "i'm using fall 2015, math, course 1190". https://owlexpress.kennesaw.edu/prodban/bwckschd.p_disp_dyn_sched
when run code below, outputs returns string goes webbrowser component. shows:
class schedule search fall semester 2015 mar 31, 2015 stop must select @ least 1 subject . i used chrome debugging find post values , set them when use site normally. included cookies in case needed those.
edit:
ok, new issue. used browser works , 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 though because uses names twice, sel_subj (and key values in 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 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; } } } }
per our discussion in comments, service posting requires set of parameters 'dummy' values , set of same params real values.
if use namevaluecollection argument going formurlencodedcontent constructor, able use duplicate keys. should work
Comments
Post a Comment