http post to login in c# -
i'm noob in c# programming.
i want implement http post login on web server. correct implemetation (test advanced rest) http post http://localhost:8080/pentaho/j_spring_security_check "j_username=admin&j_password=password" payload , application encoded content type . advanced rest, server responses 302 , redirects home (and right way).
i tried implement same thing in c# code (copied google) server responsens 500 ....
here code:
public partial class webform1 : system.web.ui.page {
private static readonly httpclient client = new httpclient(); protected void page_load(object sender, eventargs e) { } private void dorequest() { // create request using url can receive post. webrequest request = webrequest.create("http://localhost:8080/pentaho/j_spring_security_check"); // set method property of request post. request.method = "post"; // create post data , convert byte array. string postdata = "j_username=admin&j_password=password"; byte[] bytearray = encoding.utf8.getbytes(postdata); // set contenttype property of webrequest. request.contenttype = "application/x-www-form-urlencoded"; // set contentlength property of webrequest. request.contentlength = bytearray.length; // request stream. stream datastream = request.getrequeststream(); // write data request stream. datastream.write(bytearray, 0, bytearray.length); // close stream object. datastream.close(); // response. webresponse response = request.getresponse(); // display status. console.writeline(((httpwebresponse)response).statusdescription); // stream containing content returned server. datastream = response.getresponsestream(); // open stream using streamreader easy access. streamreader reader = new streamreader(datastream); // read content. string responsefromserver = reader.readtoend(); // display content. console.writeline(responsefromserver); // clean streams. reader.close(); datastream.close(); response.close(); } protected void button1_click(object sender, eventargs e) { dorequest(); } }
can me? many in advance
edit: here stack trace
system.dll!system.net.httpwebrequest.getresponse() sconosciuto
edoc_giocattolo2.dll!edoc_giocattolo2.webform1.dorequest() riga 45 c# edoc_giocattolo2.dll!edoc_giocattolo2.webform1.button1_click(object sender, system.eventargs e) riga 63 c# system.web.dll!system.web.ui.webcontrols.button.onclick(system.eventargs e) sconosciuto system.web.dll!system.web.ui.webcontrols.button.raisepostbackevent(string eventargument) sconosciuto system.web.dll!system.web.ui.webcontrols.button.system.web.ui.ipostbackeventhandler.raisepostbackevent(string eventargument) sconosciuto system.web.dll!system.web.ui.page.raisepostbackevent(system.web.ui.ipostbackeventhandler sourcecontrol, string eventargument) sconosciuto system.web.dll!system.web.ui.page.raisepostbackevent(system.collections.specialized.namevaluecollection postdata) sconosciuto system.web.dll!system.web.ui.page.processrequestmain(bool includestagesbeforeasyncpoint, bool includestagesafterasyncpoint) sconosciuto system.web.dll!system.web.ui.page.processrequest(bool includestagesbeforeasyncpoint, bool includestagesafterasyncpoint) sconosciuto system.web.dll!system.web.ui.page.processrequest() sconosciuto system.web.dll!system.web.ui.page.processrequestwithnoassert(system.web.httpcontext context) sconosciuto system.web.dll!system.web.ui.page.processrequest(system.web.httpcontext context) sconosciuto app_web_kky3vf3s.dll!asp.webform1_aspx.processrequest(system.web.httpcontext context) c# system.web.dll!system.web.httpapplication.callhandlerexecutionstep.system.web.httpapplication.iexecutionstep.execute() sconosciuto system.web.dll!system.web.httpapplication.executestep(system.web.httpapplication.iexecutionstep step, ref bool completedsynchronously) sconosciuto system.web.dll!system.web.httpapplication.pipelinestepmanager.resumesteps(system.exception error) sconosciuto system.web.dll!system.web.httpapplication.beginprocessrequestnotification(system.web.httpcontext context, system.asynccallback cb) sconosciuto system.web.dll!system.web.httpruntime.processrequestnotificationprivate(system.web.hosting.iis7workerrequest wr, system.web.httpcontext context) sconosciuto system.web.dll!system.web.hosting.pipelineruntime.processrequestnotificationhelper(system.intptr rootedobjectspointer, system.intptr nativerequestcontext, system.intptr moduledata, int flags) sconosciuto system.web.dll!system.web.hosting.pipelineruntime.processrequestnotification(system.intptr rootedobjectspointer, system.intptr nativerequestcontext, system.intptr moduledata, int flags) sconosciuto [transizione da nativo gestito]
[transizione da gestito nativo]
system.web.dll!system.web.hosting.pipelineruntime.processrequestnotificationhelper(system.intptr rootedobjectspointer, system.intptr nativerequestcontext, system.intptr moduledata, int flags) sconosciuto system.web.dll!system.web.hosting.pipelineruntime.processrequestnotification(system.intptr rootedobjectspointer, system.intptr nativerequestcontext, system.intptr moduledata, int flags) sconosciuto [transizione appdomain]
edit: added cast (httpwebrequest) , have not 500 internal error. can't see post request in firebug , i'm not logged in server :(
so, don't have error. printed html response (as text in console) , looks same of source page html obtained manual login. if redirect server, i'm not logged in!
any suggestion?
Comments
Post a Comment