2013-02-12 28 views
0

嗨,人們即時通訊新的C#我試圖發佈一些隱藏的領域的形式,我試過所有我發現的方法,但我似乎無法發送參數一個aspx形成這些都試過編碼如何通過/讀取從Post方法在C#中的值

using (WebClient client = new WebClient()) 
     { 
      NameValueCollection postData = new NameValueCollection() 
    { 
      { "s_transm", "TEST" }, 
      { "c_referencia", "TEST" } 
    }; 

      var result =client.UploadValues(Parameters,"POST",postData); 
     } 
     return true; 

我的零件另外一個是低谷的HttpWebRequest

public bool Pay(string Parameters) 
    { 
     HttpWebRequest httpWReq = 
      (HttpWebRequest)WebRequest.Create(Parameters); 
     var encoding = new ASCIIEncoding(); 
      string postData = string.Format("s_transm=TEST"); 
      byte[] data = 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(); 
     return true; 
    } 

和工作與窗體上的客戶端,點擊發布,這樣做只有一個直接,但我想要避免這個

<input id="Submit1" type="submit" value="submit" /> 

這是我一直在試圖讀取

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(); 
    } 
+1

我測試了你的代碼示例對http://posttestserver.com/post。 PHP,他們都工作正常。 ''參數''必須是你的URI。您確定您正在將「發送」代碼指向您在「接收」代碼中監控的網址嗎? – Nathan 2013-02-12 01:45:49

+0

是的,我也放棄了它並追蹤它 – user1742179 2013-02-12 03:22:09

+0

然後還有別的東西你沒有向我們展示。我試着用收到的樣本發送樣本,一切都按預期工作:s1 == null; s4 ==「TEST」; s2 ==「TEST」;結果==取決於發送樣本,「s_transm = TEST」或「s_transm = TEST&c_referencia = TEST」。 – Nathan 2013-02-12 04:50:07

回答

0
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)); 
     for (int i = 0; i < 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(); 
    } 
} 
+0

Hai,這個方法可以完美地在兩個網頁之間發佈數值..... By Bala(chennai軟件工程師) – Bala 2013-06-14 08:54:05

相關問題