2017-03-19 20 views
0

我有一個網站,我必須登錄到另一個網站。訪問相同的數據庫的網站。我知道我們可以使用數據庫來做,但客戶端並不接受。所以我們創建了一箇中間頁面來做到這一點。我們通過發送查詢字符串中的數據來嘗試它。但是當我們進行加密時,URL的大小就會變大。所以我與一位高級主管討論了他在PHP團隊中的工作,他讓我使用POST方法在網站上發佈數據。我沒有得到我如何做到這一點。如何使用郵政頁面在C#

請建議。

下面是我的代碼:

登錄頁面上的第一個網站:

Response.Redirect(http://ghhghg.com/TestingLogin.aspx?jaj=" +hdfUserName.Value.Trim() + "&ghhhg=" + hdfpassword.Value.Trim(); 

和頁面 「TestingLogin」 頁面的加載:從上面的代碼

string username = string.Empty; 
    string password = string.Empty; 

    if (!string.IsNullOrEmpty(Request.QueryString["jaj"])) 
    { 
     username = Convert.ToString(Request.QueryString["jaj"]); 
    } 

    if (!string.IsNullOrEmpty(Request.QueryString["ghhhg"])) 
    { 
     password = Convert.ToString(Request.QueryString["ghhhg"]); 
    } 

我已刪除加密。

請幫幫我。

回答

0

使用他的代碼是bettter在服務器端後,我使用幾年的代碼,

C#代碼

public string HttpPost(string URI, string Parameters) 
    { 
     System.Net.WebRequest req = System.Net.WebRequest.Create(URI); 
     // req.Proxy = new System.Net.WebProxy(ProxyString, true); 
     //Add these, as we're doing a POST 
     req.ContentType = "application/x-www-form-urlencoded"; 
     req.Method = "POST"; 
     //We need to count how many bytes we're sending. Post'ed Faked Forms should be name=value& 
     byte[] bytes = System.Text.Encoding.ASCII.GetBytes(Parameters); 
     req.ContentLength = bytes.Length; 
     System.IO.Stream os = req.GetRequestStream(); 
     os.Write(bytes, 0, bytes.Length); //Push it out there 
     os.Close(); 
     System.Net.WebResponse resp = req.GetResponse(); 
     if (resp == null) return null; 
     System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream()); 
     return sr.ReadToEnd().Trim(); 
    } 

我希望這將幫助你:)

相關問題