summaryrefslogtreecommitdiff
path: root/plugins/Watrack/myshows/i_cookies.inc
blob: 82c12f3b3db3b4f7794eb23bbd02203741e34129 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
{}
const
  cookies:pAnsiChar=nil;

function SendRequestCookies(url:PAnsiChar;useCookies:boolean):pAnsiChar;
var
  nlu:TNETLIBUSER;
  req :TNETLIBHTTPREQUEST;
  resp:THANDLE;
  hTmpNetLib:THANDLE;
  bufLen:int;
  pBuf:PAnsiChar;
  nlh:array [0..10] of TNETLIBHTTPHEADER;
begin
  result:=nil;

  FillChar(req,SizeOf(req),0);
  req.requestType:=REQUEST_GET;
  req.szUrl      :=url;
  req.flags      :=NLHRF_NODUMP or NLHRF_HTTP11;

  if useCookies and (cookies<>nil) then
  begin
    nlh[0].szName :='Cookie';
    nlh[0].szValue:=cookies;

    req.headers     :=@nlh;
    req.headersCount:=1;
  end;

  FillChar(nlu,SizeOf(nlu),0);
  nlu.flags := NUF_HTTPCONNS or NUF_NOHTTPSOPTION or NUF_OUTGOING or NUF_NOOPTIONS;
  nlu.szSettingsModule:='dummy';
  hTmpNetLib:=Netlib_RegisterUser(@nlu);

  resp:=Netlib_HttpTransaction(hTmpNetLib,@req);
  if resp<>0 then
  begin
    if Netlib_HttpResult(resp)=200 then
    begin
      pBuf := Netlib_HttpBuffer(resp,bufLen);
      if pBuf<>nil then
        StrDup(result,pBuf,bufLen)
      else
        result:=PAnsiChar(200);
      if not useCookies then
        cookies := Netlib_HttpCookies(resp);
    end
    else
    begin
      result:=pAnsiChar(int_ptr(Netlib_HttpResult(resp) and $0FFF));
    end;
    Netlib_FreeHttpRequest(resp);
  end;

  Netlib_CloseHandle(hTmpNetLib);
end;