Delphi Can

Orjinalini görmek için tıklayınız: IdHTTP HTTP/1.1 405
Şu anda (Arşiv) modunu görüntülemektesiniz. Orjinal Sürümü Görüntüle internal link
Merhaba,

Aşağıdaki kodlarla "delphican.com" sorunsuz çalışıyor "amazon.com" HTTP/1.1 405 Method Not Allowed hatası alıyorum.
Hatayı araştırdığımda UserAgent ile ilgili yazılar okudum fakat sorunu bir türlü çözemedim.

Sonunu nasıl çözerim?

First chance exception at $75EC0B42. Exception class EIdHTTPProtocolException with message 'HTTP/1.1 405 Method Not Allowed'. Process Amazonlar.exe (8212)

function TMainForm.AmazonSearch(Const Search: String): String;
var
  IdHTTP: TIdHttp;
  Request: TStringList;
begin
  Request := TStringList.Create;
  IdHTTP := TIdHttp.Create;
  try
    IdHTTP.AllowCookies := True;
    IdHTTP.HandleRedirects := True;
    IdHTTP.Request.ContentType := 'application/x-www-form-urlencoded';

 //   IdHTTP.Request.UserAgent := 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:42.0) Gecko/20100101 Firefox/42.0';

    IdHTTP.Post('https://www.amazon.com/', Request);
    Result := IdHTTP.Get('https://www.amazon.com/'); // https://www.amazon.com/s?k=car+parts
  finally
    IdHTTP.Free;
    Request.Free;
  end;
end;



procedure TMainForm.Button1Click(Sender: TObject);
var
  I: Integer;
  ResultHtml: String;
  Line, Rows, Doc: OleVariant;
begin
  TButton(Sender).BeginUpdate;
  ResultHtml := AmazonSearch('s?k=car+parts');
  Doc := coHTMLDocument.Create as IHTMLDocument2;
  Doc.Write(ResultHtml);
  Doc.Close;
  try
    Rows := Doc.Body.All.Tags('span'); // Spandan verileri almaya başlıyoruz
    for I := 0 to Rows.Length - 1 do
    begin
      Line := Rows.Item(I);
      if Line.className = 'welcome' then
      begin
        Memo1.Lines.Add(Rows.Item(I).InnerText)
      end;
    end;
  finally
    TButton(Sender).EndUpdate;
  end;
end;
var
   IdHttp               : TIdHttp; 
   IdSSLIOHandlerSocket : TIdSSLIOHandlerSocketOpenSSL;
try
   IdSSLIOHandlerSocket.PassThrough        := True;
   IdSSLIOHandlerSocket.SSLOptions.Method  := TIdSSLVersion.sslvTLSv1_2;

   IdHttp.IOHandler            := IdSSLIOHandlerSocket;
   IdHttp.HandleRedirects      := True; // Yeni URL path yönlendirilirse izin versin...
   IdHttp.Request.UserAgent    := 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36'; // 'Dalvik/2.1.0 (Linux; U; Android 8.0.0; SM-N950F Build/R16NW)';

(22-09-2022, Saat: 08:29)Hayati Adlı Kullanıcıdan Alıntı: [ -> ]
var
   IdHttp               : TIdHttp; 
   IdSSLIOHandlerSocket : TIdSSLIOHandlerSocketOpenSSL;
try
   IdSSLIOHandlerSocket.PassThrough        := True;
   IdSSLIOHandlerSocket.SSLOptions.Method  := TIdSSLVersion.sslvTLSv1_2;

   IdHttp.IOHandler            := IdSSLIOHandlerSocket;
   IdHttp.HandleRedirects      := True; // Yeni URL path yönlendirilirse izin versin...
   IdHttp.Request.UserAgent    := 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36'; // 'Dalvik/2.1.0 (Linux; U; Android 8.0.0; SM-N950F Build/R16NW)';



amazon.com deneyince bu hatayı veriyor
First chance exception at $75EC0B42. Exception class EIdHTTPProtocolException with message 'HTTP/1.1 405 Method Not Allowed'. Process Amazonlar.exe (11548)

Böyle bir forum buldum ama anlamadım
https://docs.aws.amazon.com/silk/latest/...agent.html
https://developers.whatismybrowser.com/u...ng/amazon/


function TMainForm.AmazonSearch(Const Search: String): String;
var
  IdHTTP: TIdHttp;
  Request: TStringList;
  IdSSLIOHandlerSocket: TIdSSLIOHandlerSocketOpenSSL;
begin
  Request := TStringList.Create;
  IdHTTP := TIdHttp.Create;
  try
    IdHTTP.AllowCookies := True;
    IdHTTP.HandleRedirects := True;
    IdSSLIOHandlerSocket.PassThrough := True;
    // IdSSLIOHandlerSocket.SSLOptions.Method := TIdSSLVersion.sslvTLSv1_2; /////PASİF YAPTIM HATA VERİYOR///////////////
    // IdHTTP.IOHandler := IdSSLIOHandlerSocket; /////PASİF YAPTIM HATA VERİYOR///////////////
    IdHTTP.HandleRedirects := True; // Yeni URL path yönlendirilirse izin versin...
    IdHTTP.Request.UserAgent := 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36'; // 'Dalvik/2.1.0 (Linux; U; Android 8.0.0; SM-N950F Build/R16NW)';

    IdHTTP.Request.ContentType := 'application/x-www-form-urlencoded';
    IdHTTP.Post('https://www.amazon.com/', Request);
    Result := IdHTTP.Get('https://www.amazon.com/'); // https://www.amazon.com/s?k=car+parts
  finally
    IdHTTP.Free;
    Request.Free;
  end;
end;





delphican.com deneyince bu şekilde sorun yok
function TMainForm.AmazonSearch(Const Search: String): String;
var
  IdHTTP: TIdHttp;
  Request: TStringList;
  IdSSLIOHandlerSocket: TIdSSLIOHandlerSocketOpenSSL;
begin
  Request := TStringList.Create;
  IdHTTP := TIdHttp.Create;
  try
    IdHTTP.AllowCookies := True;
    IdHTTP.HandleRedirects := True;
    IdSSLIOHandlerSocket.PassThrough := True;
    // IdSSLIOHandlerSocket.SSLOptions.Method := TIdSSLVersion.sslvTLSv1_2; /////PASİF YAPTIM HATA VERİYOR///////////////
    // IdHTTP.IOHandler := IdSSLIOHandlerSocket; /////PASİF YAPTIM HATA VERİYOR///////////////
    IdHTTP.HandleRedirects := True; // Yeni URL path yönlendirilirse izin versin...
    IdHTTP.Request.UserAgent := 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36'; // 'Dalvik/2.1.0 (Linux; U; Android 8.0.0; SM-N950F Build/R16NW)';

    IdHTTP.Request.ContentType := 'application/x-www-form-urlencoded';
    IdHTTP.Post('http://www.delphican.com/', Request);
    Result := IdHTTP.Get('http://www.delphican.com/'); // https://www.amazon.com/s?k=car+parts
  finally
    IdHTTP.Free;
    Request.Free;
  end;
end;
IdHTTP1.Request.ContentType := 'application/json';

IdHTTP1.Request.ContentEncoding := 'utf-8';


Denermisiniz...
(22-09-2022, Saat: 19:45)mcuyan Adlı Kullanıcıdan Alıntı: [ -> ]
IdHTTP1.Request.ContentType := 'application/json';

IdHTTP1.Request.ContentEncoding := 'utf-8';


Denermisiniz...


Yok hocam oladı 5 gündür uğraşıyoroum. Sad
IdHTTP.Post
yapmanıza gerek var mı get ile text veriyi almak istemiyor musunuz
(23-09-2022, Saat: 08:45)narkotik Adlı Kullanıcıdan Alıntı: [ -> ]IdHTTP.Post
yapmanıza gerek var mı get ile text veriyi almak istemiyor musunuz


IdHTTP.Post ile o sayfayı alıyor diye biliyorum. Ben döngü ile en son sayfaya kadar olan verileri lmak isityorum.