sas curl登录到安全的动态网站

时间:2013-11-22 04:02:03

标签: curl sas

论坛新手。我想知道是否有人知道Curl如何使用SAS处理动态页面。例如,我尝试使用下面的类似代码来卷曲Base SAS中的动态页面:https://mysite.com/kl/livelink.exe?func=ll&objId=123,结果显示'objId'不被识别为内部或外部命令,可操作程序或批处理文件。程序或批处理文件。有人有什么想法吗?在此先感谢。

%let a = ll;
%let b = 1117016710;
data _null_;
  call symput ('curl_cmd', "&curl_executable -k -u &userpass %nrstr(https://mysite.com/kl/livelink.exe?func=)&a^%nrstr(&objId=)&b ");
run;

filename curl pipe "&curl_cmd" lrecl=32767;
data tmp;
  length xml $&maxchars;
  infile curl truncover end=eof;
  input @1 xml $&maxchars..; 
  if lengthn(xml) ge &maxchars then do;      
    put "ERROR: FAILED FOR process BECAUSE XML WAS > &maxchars CHARS";
    put "OBSERVATION: " _n_;
    put xml;
    stop;
  end;
run;
filename curl clear;

the results shows:
filename curl pipe "&curl_cmd" lrecl=32767;
WARNING: Apparent symbolic reference OBJID not resolved.

 PROCESS=C:\test\curl\curl.exe -k -u user:pwd
      https://mysite.com/kl/livelink.exe?func=ll^&objId=1117016710,
      RECFM=V,LRECL=32767

Stderr output:
   Total     Received  Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0
   0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
NOTE: 0 records were read from the infile CURL.
NOTE: The data set WORK.TMP has 0 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.35 seconds

在Joe的建议之后,我做了一些更改,以下是结果:

%let curl_executable = C:\test\curl\curl.exe;
%let maxchars        = 3000;
%let userpass        = user:pwd;

%let a = ll;
%let b = 1117016710;
%let curl_cmd=&curl_executable -k -u &userpass %nrstr(https://mysite.com/kl/livelink.exe?func=)&a.%nrstr(&objId)=&b ;
%put &=curl_cmd;

data _null_;
  call symput ('curl_cmd', '&curl_executable -k -u &userpass %nrstr(https://mysite.com/kl/livelink.exe?func=)&a.%nrstr(&objId)=&b');
run;
%put &=curl_cmd;

filename curl pipe "&curl_cmd" lrecl=32767;
data tmp;
  length xml $&maxchars;

  infile curl truncover end=eof;
  input @1 xml $&maxchars..;

  if lengthn(xml) ge &maxchars then do;      
    put "ERROR: FAILED FOR process BECAUSE XML WAS > &maxchars CHARS";
    put "OBSERVATION: " _n_;
    put xml;
    stop;
  end;
run;
filename curl clear;

结果日志文件返回:

37   %let curl_executable = C:\test\curl\curl.exe;
38   %let maxchars        = 3000;
39   %let userpass        = user:pwd;
40   %let a = ll;
41   %let b = 1117016710;
42   %let curl_cmd=&curl_executable -k -u &userpass
42 ! %nrstr(https://mysite.com/kl/livelink.exe?func=)&a.%nrstr(&objId)=&b
42 ! ;
43   %put &=curl_cmd;
CURL_CMD=C:\test\curl\curl.exe -k -u user:pwd
https://mysite.com/kl/livelink.exe?func=ll&objId=1117016710
44
45   data _null_;
46     call symput ('curl_cmd', '&curl_executable -k -u &userpass
46 ! %nrstr(https://mysite.com/kl/livelink.exe?func=)&a.%nrstr(&objId)=&b'
46 ! );
47   run;

NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


48   %put &=curl_cmd;
CURL_CMD=C:\test\curl\curl.exe -k -u user:pwd
https://mysite.com/kl/livelink.exe?func=ll&objId=1117016710
49
50   filename curl pipe "&curl_cmd" lrecl=32767;
51   data tmp;
52     length xml $&maxchars;
53
54     infile curl truncover end=eof;
55     input @1 xml $&maxchars..;
56
57     if lengthn(xml) ge &maxchars then do;
58       put "ERROR: FAILED FOR process BECAUSE XML WAS > &maxchars CHARS";
59       put "OBSERVATION: " _n_;
60       put xml;
61       stop;
62     end;
63   run;

NOTE: The infile CURL is:
      Unnamed Pipe Access Device,

      PROCESS=C:\test\curl\curl.exe -k -u user:pwd
      https://mysite.com/kl/livelink.exe?func=ll&objId=1117016710,
      RECFM=V,LRECL=32767

Stderr output:
   Total     Received  Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0
   0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
'objId' is not recognized as an internal or external command,
operable program or batch file.
NOTE: 0 records were read from the infile CURL.
NOTE: The data set WORK.TMP has 0 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.43 seconds
      cpu time            0.04 seconds


64   filename curl clear;
NOTE: Fileref CURL has been deassigned.
65
66
67   proc print data=tmp;
68   run;

NOTE: No observations in data set WORK.TMP.
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

2 个答案:

答案 0 :(得分:0)

关于宏OBJID无法识别的警告很烦人但不是问题。这只是说URL中的& OBJID没有解析。没关系,你想要& OBJID。

我怀疑您的问题是网址中的^字符。我怀疑您需要.来描述&a宏变量。

你真的想要网址是mysite.com/kl/livelink.exe?func=ll ^& objId = 1117016710? (增加空格以帮助它脱颖而出)

答案 1 :(得分:0)

如果它实际上没有解决您的问题,这可能有助于简化错误检查:

使用%let来定义宏变量,而不是CALL SYMPUT,除非你有充分的理由去做后者。在这种情况下,由于您使用宏变量作为组件,因此您可能没有充分的理由。

%let a = ll;
%let b = 1117016710;
%let curl_executable=c:\curl.exe;
%let userpass=password;

%let curl_cmd=&curl_executable -k -u &userpass %nrstr(https://mysite.com/kl/livelink.exe?func=)&a%nrstr(&objId=)&b ;
%put &=curl_cmd;

其次,如果你使用电话交谈,要避免警告,你可以把它放在单引号中。不用担心,当它实际使用时,它仍会得到解决。

data _null_;
  call symput ('curl_cmd', '&curl_executable -k -u &userpass %nrstr(https://mysite.com/kl/livelink.exe?func=)&a%nrstr(&objId=)&b');
run;
%put &=curl_cmd;

(旁注:& =仅适用于9.3+,所以如果您有9.2,请删除=)