![]() |
| ||
|
|
Новости |
Поиск |
FAQ |
Статьи |
Книги |
Новости VCL
| | Форумы ЧАТ |
Орешник |
|
| |||
| |||
« предыдущая ветвь | форум | следующая ветвь »
Пересылка UTF-8 запроса с использованием TidHTTP [D7, WinXP]
olegl © (2005-09-01 12:27:00)Нужно переслать запрос UTF-8 из клиентского приложения с использованием TidHTTP. Получение данных запроса происходит нормально, а вот при отсылке сервер интерпретирует символы выше таблицы ASCII как некорректные. Подозреваю что функция UTF8Encode преобразует данные в непонятный для сервера формат или INDY не правельно пересылает данные. Сервер - Java-сервлет, TOMCAT/Apache. Перед самой отсылкой запроса пробовал данные скидывать в файл, все OK.
Код:
procedure TSocketThread.Initialize(ConnectionType: TConnectionType; Login,
Password, Host: string; Port: integer);
begin
FResponseReady:=false;
FConnectionType:=ConnectionType;
FHTTP.Request.Username:=Login;
FHTTP.Request.Password:=Password;
FHTTP.Request.Host:=Host;
FHTTP.Host:=Host;
FHTTP.Port:=Port;
FHTTP.Request.ContentType:= 'application/x-www-form-urlencoded;text/xml; charset=utf-8;';
//FHTTP.Request.ContentType:= 'text/xml; charset=UTF-8;';
FHTTP.Request.BasicAuthentication:=true;
FInitialized:=true;
end;
procedure TSocketThread.Execute;
var
sOut,sInp: TMemoryStream;
Request: WideString;
sStr:TtntStringList;
ANSIResponse,ANSIRequest:string;
const
jndiName = 'lv/gcpartners/psi/webmodule/EntryPoint';
begin
SetName;
FWorking:=true;
sInp:=TMemoryStream.Create;
sOut:=TMemoryStream.Create;
Request:=('jndiname='+jndiName+'&xmlmessage='+FRequest);
ANSIRequest:=UTF8Encode(Request);
sInp.Write((@ANSIRequest[1])^,length(ANSIRequest)); // Проблема тут !!!
try
try
if sHost='' then
raise Exception.Create('sHost field empty in TSocketThread.Execute');
if FRequest='' then
raise Exception.Create('Request field empty in TSocketThread.Execute');
if FHTTP.Host='' then
raise Exception.Create('TSocketThread not initialized in TSocketThread.Execute');
if not assigned(FHTTP) then
raise Exception.Create('TidHTTP not created in TSocketThread.Execute');
FHTTP.Post('http://'+FHTTP.Request.Host+sHost, sInp, sOut); // или тут... наверно :)
FResponse.ResponseResult:=rrOk;
except
on E: Exception do
begin
FResponse.ErrorStr:=e.Message;
FResponse.ResponseResult:=rrError;
end;
end;
finally
if FHTTP.ResponseCode=200 then
FResponse.ResponseResult:=rrOk
else if FHTTP.ResponseCode=401 then
begin
FResponse.ResponseResult:=rrError;
FResponse.ErrorStr:='Bad login information.' +#13#10+'Please re-type Username and Password carefully.';
end
else FResponse.ResponseResult:=rrError;
sOut.Seek(0,soFromBeginning);
SetLength(ANSIResponse,sOut.Size);
sOut.Read((@ANSIResponse[1])^,sOut.Size);
FResponse.XMLResponse:=UTF8Decode(ANSIResponse);
FHTTP.Free;
SInp.Free;
sOut.Free;
FRequest:='';
FResponseReady:=true;
FWorking:=false;
end;
end;
olegl (2005-09-01 12:33:00) [1]Наверно стоит дополнить что если запрос не содержит нелатнских символов то все OK