IdHTTP Post -> Response mit lateinischen und chinesischen Zeichen
Folgenden Code verwende ich für ein POST einer php Seite:
Code:
Als Antwort bekomme ich dann zb.:function SendPostData(Ahttp: TIdHTTP; const AtoURL: String; const aParams: TStrings): String; Var lStream: TMemoryStream; lParams: TStringStream; I: Integer; begin Result:=''; if not Assigned(aHttp) then exit; lStream := TMemoryStream.create; lParams := TStringStream.create(''); try AHTTP.Request.CustomHeaders.AddValue('X-Requested-With', 'XMLHttpRequest'); AHTTP.Request.Host := Form1.Edit1.Text; AHTTP.Request.UserAgent := 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:53.0) Gecko/20100101 Firefox/53.0'; AHTTP.Request.Accept := '*/*'; AHTTP.Request.AcceptLanguage := 'de,en-US;q=0.7,en;q=0.3'; AHTTP.Request.AcceptEncoding := 'gzip, deflate'; AHTTP.Request.Referer := Form1.Edit2.Text; AHTTP.Request.ContentType := 'application/x-www-form-urlencoded'; AHTTP.Request.CharSet := 'UTF-8'; AHTTP.Request.ContentLength := 31; AHTTP.Request.Connection := 'keep-alive'; for I:=0 to aParams.Count-1 do lParams.WriteString(aParams[I] + '&'); try AHTTP.Post(AtoURL, lParams, lStream); except on E: Exception do showmessage('Fehler bei der Übertragung: ' + E.Message); end; SetLength(Result, lStream.Size); lStream.Position := 0; lStream.ReadBuffer(Result[1], lStream.Size); finally lParams.Free; lStream.Free; end; end; procedure TForm1.Button1Click(Sender: TObject); var xStr : TStringList; xIdHTTP : TIdHTTP; begin xIdHTTP := TIdHTTP.Create(nil); xStr := TStringList.Create; try xIdHTTP.HandleRedirects := True; xIdHTTP.IOHandler := IdSSLIOHandlerSocketOpenSSL1; xIdHTTP.CookieManager := IdCookieManager1; xIdHTTP.Compressor := IdCompressorZLib1; xIdHTTP.AllowCookies := True; xStr.Text := Memo2.Text; Memo1.Text := SendPostData(xIdHTTP, AdvEdit3.Text, xStr); finally xStr.Free; xIdHTTP.Free; end; end; 敳呴浩潥瑵昨湵瑣潩⡮笩搠捯浵湥摪慟摤献扵業⡴ ⱽ㔠〰 㱽猯牣灩㹴.html</a></div><div class="ap1"></div></div><div class="ap0"><div class="ap2">Seite 2</div> Ein Teil ist chinesisch und ein Teil lateinisch. Im Firefox funktioniert der "manuelle" POST einwandfrei. Da sehe ich auch die Antwort komplett in latein und keine chinesischen Zeichen. Hat Jemand eine Idee wieso in Delphi chinesische Zeichen angezeigt werden, statt lateinischen? |
AW: IdHTTP Post -> Response mit lateinischen und chinesischen Zeichen
Um einen HTML String als Response zu erhalten würde ich diesen Weg wählen:
Delphi-Quellcode:
Die anderen Post.Overloads braucht man vermtlich eher für binäre Responsetypen.
var
HTTP: TIdHTTP; RequestBody: TStream; ResponseBody: string; ... ResponseBody := HTTP.Post('https://example.org', RequestBody); |
AW: IdHTTP Post -> Response mit lateinischen und chinesischen Zeichen
Hallo mjustin,
vielen dank für die schnelle Antwort. Das hat tatsächlich geholfen :thumb: Beste Grüße Bogdan |
Alle Zeitangaben in WEZ +1. Es ist jetzt 02:19 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz