我發佈了兩種形式 - 一種在c#中,另一種在delphi中。但結果字符串似乎是不同的:delphi vs c#post返回不同的字符串 - utf問題?
C#的回報:¤@@[email protected]@@@[email protected]@@@[email protected]@xśm˱Â0Đ...
德爾福回報:#$1E'@@[email protected]@@@[email protected]@@@[email protected]@x'#$009C...
和SICE都被壓縮流遇到錯誤,而試圖將其解壓... 的C#是'正確' - 即。提取物。我不是delphi的專家 - 我只需要將一些代碼從c#轉換爲delphi。
C#代碼:
string GetData(Hashtable aParam, string ServerURL)
{
string Result = "";
WebRequest Request = HttpWebRequest.Create(ServerURL);
Request.Method = "POST";
Request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
UTF8Encoding encUTF8 = new System.Text.UTF8Encoding(false);
StreamWriter writer = new StreamWriter(Request.GetRequestStream(), encUTF8);
foreach (DictionaryEntry element in aParam)
{
writer.Write(element.Key + "=" + element.Value + "&");
}
writer.Close();
writer.Dispose();
WebResponse Response = Request.GetResponse();
StreamReader Reader = new StreamReader(Response.GetResponseStream(), System.Text.Encoding.Default);
Result = Reader.ReadToEnd();
Reader.Close();
Response.Close();
Reader.Dispose();
return Result;
}
Delphi代碼:
function GetData(aParam:TStringList; ServerURL:string):string;
var
req: TIdHTTP;
res: string;
begin
req := TIdHTTP.Create();
with req do
begin
Request.ContentType := 'application/x-www-form-urlencoded; charset=UTF-8';
Request.Method := 'POST';
Request.CharSet := 'utf-8';
Request.AcceptCharSet := 'utf-8';
res := Post(ServerURL, aParam);
end;
Result := res;
req.Free;
end;
CNC中 我使用德爾福2010
哪個版本是正確的,可以解壓?使用Fiddler2等工具來監控實際正在進行的HTTP流量可能會很好。這將允許您查看請求中的差異。 – 2010-06-15 10:46:59
c#版本是正確的,我只想着提琴手... – argh 2010-06-15 11:02:11
我想我找到了原因: 'TIdHTTP.Post()不支持從TStringList中發佈Unicode。您必須首先將Unicode保存到單獨的TStream中,然後將其發佈。# – argh 2010-06-15 11:35:22