отправка Http запроса
Как отправить HTTP-запрос на указанный, чтобы скрипт его обработал, и получить ответ!???
Попробуй использовать класс TWebRequest, там в принципе и кмпонентов много, которые тебе помогут.
А вот как с постом?
{ .... }
procedure TForm1.Button1Click(Sender: TObject);
var
data: TIdMultiPartFormDataStream;
begin
data := TIdMultiPartFormDataStream.Create;
try
{ add the used parameters for the script }
data.AddFormField('param1', 'value1');
data.AddFormField('param2', 'value2');
data.AddFormField('param3', 'value3');
{ Call the Post method of TIdHTTP and read the result into TMemo }
Memo1.Lines.Text := IdHTTP1.Post('http://localhost/script.php', data);
finally
data.Free;
end;
end;
только вот он у меня не работает. не может MultiPartFormData распознать.
Да я разобрался как с ГЕТом отправлять.
А вот как с постом?
{ .... }
procedure TForm1.Button1Click(Sender: TObject);
var
data: TIdMultiPartFormDataStream;
begin
data := TIdMultiPartFormDataStream.Create;
try
{ add the used parameters for the script }
data.AddFormField('param1', 'value1');
data.AddFormField('param2', 'value2');
data.AddFormField('param3', 'value3');
{ Call the Post method of TIdHTTP and read the result into TMemo }
Memo1.Lines.Text := IdHTTP1.Post('http://localhost/script.php', data);
finally
data.Free;
end;
end;
только вот он у меня не работает. не может MultiPartFormData распознать.
Попробуй на прямую:
Declaration
function Post(AURL: string, ASource: TStrings): string; overload;
Parameters
Parameters Description
ASource TStrings or stream containing the request data.
URL Location of the host or CGI application.
Returns
String - Values received in a Response for the HTTP POST method.
Description
Post is an overloaded method in TIdHTTP that is used to send data specified in ASource to the resource location in AURL. Post is overloaded to allow use of either TStrings or TStream object instances in ASource, and also provides procedure- and function-based variants of the method to allow String return values or storage of return values in AResponseContent.
Indy currently reverts the HTTP version to 1.0 in a call to the Post method. This occurs because some HTTP servers do not respect the RFC for HTTP 1.1 to the full extent of the specification. In particular, most servers do not send or expect to receive the 100-Continue HTTP header. Until an optimum solution that does NOT break the RFC is discovered, Indy will restrict all POST requests to version HTTP 1.0 compliance.
When ASource is a TStrings instance, Post will replace all occurrences of the End-Of-Line (EOL) character in ASource with the value '&' prior to transfer to the HTTP server. When ASource is a TStream instance, no preprocessing of the stream content is performed.
Post calls the protected method used to perform the HTTP transfer.
можешь пример показать?
А что мне писать в ASource?
можешь пример показать?
Примера у меня конечно нет, но вот судя по этому куску, который я тебе дал.
В каждой строчке нужно будет указать
параметр=значение. Попробуй так, на самом деле, туда в качестве ASource, можно передать и поток(TStream). Поэкспереминтируй. Или подожди пока я сам разбирусь до конца.
И еще, а ты в uses дописал IdMultipartFormData???? Что б он у тебя класс нормально определял или так прям зашарашил???