if _msg.isRequest then
begin
req:= THTTPRequest(_msg);
msgBody:= req.getMessageBody;
// Adds the URI line.
str:= str + req.getMethod + ' ';
str:= str + req.getURI + ' ';
str:= str + versionText + CRLF;
// Sets the content length header if its a POST
if req.getMethod = 'POST' then
req.setHeader(THTTPHeaderKey.CONTENT_LENGTH.ToString, IntToStr(Length(msgBody) * SizeOf(Char)));
// Adds the headers
for i:= 0 to req.getHeaders.Count -1 do
str:= str + req.getHeaders.Names[i] + '=' + req.getHeaders.ValueFromIndex[i];
str:= str + CRLF;
// Adds the message body if its POST
if req.getMethod = 'POST' then
str:= str + msgBody;
// Writes the result to the output stream.
formPopupRemote.IdTCPClient1.IOHandler.Write(Byte(str)); -> ERROR LINE
// formPopupRemote.HTTP.Get(str, stream);
end
else
ShowMessage('Responses sending not yet supported!');
end;
Я хочу записать результат в IOHandler. Но как я могу это сделать, я преобразовал этот код из JAVA.TIdTCPClient Write Bytes
Вот Java коды:
if (_msg.isRequest()) {
HTTPRequest req = (HTTPRequest) _msg;
String msgBody = req.getMessageBody();
// Adds the URI line.
str.append(req.getMethod() + " ");
str.append(req.getURI() + " ");
str.append(versionText + CRLF);
// Sets the content length header if its a POST
if (req.getMethod() == HTTPRequest.Method.POST)
req.setHeader(HTTPHeaderKey.CONTENT_LENGTH.toString(), String.valueOf(msgBody.getBytes().length));
// Adds the headers
for (String key : req.getHeaders())
str.append(key + ": " + req.getHeader(key) + CRLF);
str.append(CRLF);
// Adds the message body if its POST
if (req.getMethod() == HTTPRequest.Method.POST)
str.append(msgBody);
// Writes the result to the output stream.
getOutputStream().write(str.toString().getBytes());
} else {
throw new ProtocolException("Responses sending not yet supported!");
}
}
На самом деле я хочу, чтобы преобразовать в Delphi из Java-кодов. Но я не мог найти выходной поток равным в Delphi. Поскольку TIdClient.IOHandler.Write не имеет параметра TBytes
или array of Byte
. Но параметр выходного потока равен array of byte
. Так как я должен писать str
?
Использовать 'TIdHttp'client вместо TIdTCPclient, он поддерживает запросы POST ... – whosrdaddy
Вы могли бы дать мне образец? –
Что случилось с вашим вчерашним вопросом относительно IOHandler.ReadStream(). Мне было бы интересно узнать, что издевательствовала ваша проблема. –