PDA

View Full Version : خواندن اطلاعات کوکی ها در دلفی



baran_2005
پنج شنبه 13 آبان 1389, 09:48 صبح
سلام من یک پروژه دارم که در اون یک رمز از دلفی با استفاده از idhttp فرستاده می شه در به روی هاست در اونجا این پسورد بررسی می شه اگر درست بود از دیتا بیس اطلاعات فرد به صورت کوکی براش فرستاده می شه .من در قسمت ارسال پسورد و بررسی اون مشکلی ندارم ولی برنامه زمانی که می خواد اطلاعات فرد رو به صورت کوکی از هاست بگیره این کار انجام نمی شه.یعنی نمی دونم چطوری باید یک کوکی رو در دلفی بخونم. این بخش برنامه رو براتون ضمیمه می کنم .خیلی بد جور گیر کردم لطفا یکی کمکم کنه.
[CODE][a:=lsbnoebar.Items.Strings[lsbnoebar.ItemIndex];
b:=AdvEdit2.Text;
c:=AdvEdit3.Text;
d:=Label5.Caption;

http:=TIdHTTP.Create(self);
SL := TSTringList.Create;
try
SL.Values['noebar']:=lsbnoebar.Items.Strings[lsbnoebar.ItemIndex];
SL.Values['hoze']:=AdvEdit2.Text;
SL.Values['shomare']:=AdvEdit3.Text;
HTTP.HandleRedirects := True;
HTTP.AllowCookies := True;
with http do
begin
Request.ContentType := 'application/x-www-form-urlencoded;';
//Request.CharSet := 'utf-8';
Request.AcceptCharSet := 'utf-8';
Request.UserAgent := 'agent2';
Request.Connection := 'Keep-Alive';
Request.ProxyConnection := 'Keep-Alive';
Request.CacheControl := 'no-cache';
http.post('http://forward2.orgfree.com/inserttable.php',SL );
end;
finally
SL.Free;
end;
end;
procedure TForm4.Button3Click(Sender: TObject);
var thisIdURI : TIdURI;
j:integer;
begin
v:=False;
http:=TIdHTTP.Create(self);
SL := TSTringList.Create;
SL.Values['shomare']:=AdvEdit3.Text;
HTTP.HandleRedirects := True;
HTTP.AllowCookies := True;
with http do
begin
Request.ContentType := 'application/x-www-form-urlencoded;';
Request.AcceptCharSet := 'utf-8';
Request.UserAgent := 'agent2';
Request.Connection := 'Keep-Alive';
Request.ProxyConnection := 'Keep-Alive';
Request.CacheControl := 'no-cache';
Memo1.text:= http.Post('http://forward2.orgfree.com/istrue2.php',SL);
thisIdURI := TIdURI.create('http://forward2.orgfree.com/istrue2.php');
thisIdURI.Host := 'localhost';
thisIdURI.URI:='http://forward2.orgfree.com/istrue2.php';
// ShowMessage(thisIdURI.URI);

memo2.Lines.Add(IdCookieManager1.GenerateCookieLis t(thisIdURI,false) ) ;
memo2.text:= IntToStr(IdCookieManager1.CookieCollection.Count);

for j := 0 to IdCookieManager1.CookieCollection.Count-1 do
begin
memo2.lines.add(IdCookieManager1.CookieCollection. Items[j].domain);
memo2.lines.add(IdCookieManager1.CookieCollection. Items[j].CookieText);
memo2.lines.add(IdCookieManager1.CookieCollection. Items[j].Expires);
memo2.lines.add(IdCookieManager1.CookieCollection. Items[j].CookieName);
memo2.lines.add(IdCookieManager1.CookieCollection. Items[j].Comment);
memo2.lines.add(IdCookieManager1.CookieCollection. Items[j].CookieText);
memo2.lines.add(IdCookieManager1.CookieCollection. Items[j].Value);

end;



//IdCookieManager1.CookieCollection.GetCookieIndex(1 ,)

end;

/CODE]

gbg
شنبه 15 آبان 1389, 20:06 عصر
کوکی از هاست گرفته نمیشه ، روی کلاینت وجود داره و همونجا هم ذخیره میشه

Peresident_y
شنبه 28 اسفند 1389, 13:18 عصر
مثال

LCookie := TStringList.Create;
with LCookie do try

LValid := Now +1;
Add('d='+TIWAdvLUEdit1.Text);
Add('SetAt=' + FormatDateTime('dd/mm/yyyy hh:mm', Now));
Add('ValidUntil=' + FormatDateTime('dd/mm/yyyy hh:mm',
LValid));
WebApplication.Response.SetCookieField(LCookie, '', '', LValid, False);
finally
FreeAndNil(LCookie);
end;
WebApplication.Request.CookieFields.Values['d']:=TIWAdvLUEdit1.Text;// مقدار دهی فیلد کوکی



TIWAdvLUEdit1.Text:=WebApplication.Request.CookieF ields.Values['d']//دریافت اطلاعات