c# 和 delphi 的 base64 編碼一致問題 webservice

來源:互聯網
上載者:User

標籤:des   http   io   os   ar   for   資料   sp   div   

c# 和 delphi 的 base64 編碼一致問題 webservice 由於項目需要為包括c/s和b/s的多個平台提供統一商務邏輯,寫個webservice來完成這個任務,通過webservice封裝商務邏輯,為其他平台提供介面,以供調用,於是用delphi寫一個webservice,起初沒有任何採用任何編碼,當然在調用的時候delphi用戶端可以正常傳輸資料,c#網頁部分調用卻是亂碼,肯定是兩種語言的編碼方式問題,引起的亂碼,原因有了,最終也沒有想到解決的辦法。所以想兩端提供一種統一的編碼,通過編碼和解碼來達到編碼方式的統一,這樣應該就不會有亂碼的問題了吧,我選擇base64編碼方式,base64在網路上良好的效能,這是滿足這個所需要的,又折騰了一陣子,終於完成了,各個平台資料的統一,測試代碼如下:

1 delphi部分:

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,EncdDecd;

type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
Button2: TButton;
Edit3: TEdit;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var s:AnsiString;
begin
s:=edit1.text;
edit2.Text:= EncodeString((s));

// 超越軟體 http://www.cyhlw.com
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
edit3.Text:=DecodeString(edit2.text)
end;

end.

2c# 部分:

using System;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Text;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

//Response.ContentEncoding = System.Text.Encoding.GetEncoding( "GB2312" );


}
protected void Button1_Click(object sender, EventArgs e)
{

string str="";


localhost.IIHelloservice oserver = new localhost.IIHelloservice();
str=oserver.sayHello("超越軟體 http://www.cyhlw.com");
//localhost.WebService1 oService = new localhost.WebService1();
//Label1.Text = oService.About();
this.TextBox1.Text = str;

byte[] bytes = System.Convert.FromBase64String(str);
str = "";
str = Encoding.Default.GetString(bytes);
TextBox2.Text = str;
//TextBox1.Text=Encoder.get
//byte[] bytes
//this.TextBox1.Text = System.Convert.FromBase64String(str);

}
}

c# 和 delphi 的 base64 編碼一致問題 webservice

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.