.net - How to Pass/Read Values From post Method in C# -
hi people im new c# i'm trying post hidden fields form i've tried methods have found cant seem able send parameters aspx form these parts of tried coding
using (webclient client = new webclient()) { namevaluecollection postdata = new namevaluecollection() { { "s_transm", "test" }, { "c_referencia", "test" } }; var result =client.uploadvalues(parameters,"post",postdata); } homecoming true;
another 1 trough httpwebrequest
public bool pay(string parameters) { httpwebrequest httpwreq = (httpwebrequest)webrequest.create(parameters); var encoding = new asciiencoding(); string postdata = string.format("s_transm=test"); byte[] info = encoding.getbytes(postdata); httpwreq.method = "post"; httpwreq.contenttype = "application/x-www-form-urlencoded"; httpwreq.contentlength = data.length; using (stream newstream = httpwreq.getrequeststream()) { newstream.write(data,0,data.length); } var r =httpwreq.getresponse(); homecoming true; }
and 1 works doing client click post on form straight want avoid
<input id="submit1" type="submit" value="submit" />
these have been trying read
protected void page_load(object sender, eventargs e) { string s1=request.querystring["s_transm"]; string s4 = request["s_transm"]; string s2 = request.form["s_transm"]; string result = new streamreader(request.inputstream).readtoend(); }
void postme2(object sender, eventargs e) { remotepost myremotepost = new remotepost(); myremotepost.url = "http://www.jigar.net/demo/httprequestdemoserver.aspx"; myremotepost.add("field1", "huckleberry"); myremotepost.add("field2", "finn"); myremotepost.post(); } public class remotepost { private system.collections.specialized.namevaluecollection inputs = new system.collections.specialized.namevaluecollection(); public string url = ""; public string method = "post"; public string formname = "form1"; public void add(string name, string value) { inputs.add(name, value); } public void post() { system.web.httpcontext.current.response.clear(); system.web.httpcontext.current.response.write("<html><head>"); system.web.httpcontext.current.response.write(string.format("</head><body onload=\"document.{0}.submit()\">", formname)); system.web.httpcontext.current.response.write(string.format("<form name=\"{0}\" method=\"{1}\" action=\"{2}\" >", formname, method, url)); (int = 0; < inputs.keys.count; i++) { system.web.httpcontext.current.response.write(string.format("<input name=\"{0}\" type=\"hidden\" value=\"{1}\">", inputs.keys[i], inputs[inputs.keys[i]])); } system.web.httpcontext.current.response.write("</form>"); system.web.httpcontext.current.response.write("</body></html>"); system.web.httpcontext.current.response.end(); } }
c# .net post
No comments:
Post a Comment