[英]Barclays encryption asp.net (VB to c#)
我正在嘗試從Barclays支付網關實現加密腳本,但它在VB中,我們網站的其余部分在c#中。
腳本是
Public Class Example
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
'The Following Creates the WebClient Object
Dim web As New System.Net.WebClient()
'The Header Content Type is then set
web.Headers.Add("Content-Type", "application/x-www-form-urlencoded")
'PostData is then declared as data type Byte and populated with the post data
Dim PostData As Byte() = System.Text.Encoding.ASCII.GetBytes("clientid=[clientid]&password=[password]&oid=[orderid]&chargetype=PreAuth¤cycode=826&total=[total]")
'The Web object is then used to upload the postdata to the Encryption URL and the response is stored in the Response variable
Dim Response As Byte() = web.UploadData("https://secure2.epdq.co.uk/cgi-bin/CcxBarclaysEpdqEncTool.e", "POST", PostData)
'The response from the post is then converted from Type Byte to String and stored in the session variable
Session("Response") = (System.Text.Encoding.ASCII.GetString(Response))
End Sub
End Class
我怎樣才能在C#aspx頁面中運行這個VB? 或者我需要將其轉換為使用c#?? 在我的aspx頁面中,我有第一行
<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="utf-8" CodeBehind="encryption.cs" %>
謝謝你的幫助。
您的整個應用程序代碼都在C#中。 因此,最好將巴克萊代碼轉換為C#。 您可以使用以下鏈接將vb代碼轉換為C#。 http://www.developerfusion.com/tools/convert/vb-to-csharp/
而不是在某個地方使用這個VB.NET代碼,轉換它會簡單得多; 而且,相信你會花時間消化它,我已經冒昧地為你這樣做了:
public class Example : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
//put user code to initialise page here
var client = new System.Net.WebClient();
client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
var data = System.Text.Encoding.ASCII.GetBytes(
"clientid=[clientid]&password=[password]&oid=[orderid]&" +
"chargetype=PreAuth¤cycode=826&total=[total]");
var response = client.UploadData(
"https://secure2.epdq.co.uk/cgi-bin/CcxBarclaysEpdqEncTool.e",
"POST", data);
Session["Response"] = System.Text.Encoding.ASCII.GetString(response);
}
}
請注意,大部分代碼都是相同的,例如通過名稱空間看起來幾乎相同來訪問框架的類型; 差異包括區分大小寫,因此我們必須使用保留字的小寫字母,如訪問描述符( public
, private
等)和new
關鍵字等等; 另外,語句在C#中以分號結束。
此外,請注意您可能需要注意的代碼的一些“問題”,例如WebClient
是一次性的 ,這里沒有正確處理的東西(也就是說,從不調用Dispose
。)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.