I am trying to write a proc http with post method in order to check login possibility to a website (SASCIStudio).
This is the code im using:
%let username=MyName;
%let pwd=password;
filename input TEMP;
filename resp TEMP;
filename headers TEMP;
/*
Macro that simply echoes the contents of a fileref to the SAS log
*/
%macro echofile(file);
data _null_;
infile &file;
input;
put _infile_;
run;
%mend;
/*
* Create the input file for the request
*/
data _null_;
file input recfm=f lrecl=1;
put "username=&username.%nrstr(&password)=&pwd";
run;
%echofile(input);
proc http
method="POST"
url="https://logon-website.com/security_check"
in=input
headerout=headers
out=resp;
run;
the echofile macro output:
username=MyName&password=password
NOTE: 1 record was read from the infile INPUT.
The output form in the resp file:
<form id="fm1" class="form-stacked" onSubmit="return setSubmitUrl(this);" action="https://logon-website.com/security_check" method="post">
<fieldset>
<legend>Sign In<sup>®</sup></legend>
<div class="clearfix">
<label for="username"><span class="accesskey">U</span>ser ID:</label>
<input id="username" name="username" class="required" tabindex="1" accesskey="u" type="text" value="" size="25" autocomplete="off"/>
</div>
<div class="clearfix">
<label for="password"><span class="accesskey">P</span>assword:</label>
<input id="password" name="password" class="required" tabindex="2" accesskey="p" type="password" value="" size="25" autocomplete="off"/>
</div>
</fieldset>
<input type="hidden" name="lt" value="LT-2117-BJYk9XdRaLUPCHpGyDvAC0sxNf6Vd7" />
<input type="hidden" name="execution" value="e1s1" />
<input type="hidden" name="_eventId" value="submit" />
<div class="submitb"><input id="Logon" type="submit" value="Sign In" onClick="this.disabled=true;this.form.submit();" tabindex="3" /></div>
</form>
Values of username and password are missing in the output form.
There are no errors as I am getting 200 OK, but i am expecting 302 FOUND. I am using SAS9.4.
Is there a way to properly use the post method and check the login possibility when provided with valid credentials?
Have you tried setting the debug level to 1 or 2 to see what's being sent?
Im afraid my SAS version does not allow it - i found that it is only available starting in SAS 9.4M5.
using this:
proc http
method="POST"
url="https://logon-website.com/security_check"
in=input
headerout=headers
out=resp;
debug level=2;
run;
causes an error:
ERROR 180-322: Statement is not valid or it is used out of proper order.
Is there any other way to see the request sent?
> Is there any other way to see the request sent?
Only 2 ways I can think of: connect to a web server you control, or use a packet analyzer such as wireshark,
Fyi, I ran this:
%let username=MyName;
%let pwd=MyPassword;
filename input TEMP;
filename resp TEMP;
filename headers TEMP;
data _null_;
file input recfm=f lrecl=1;
put "username=&username.%nrstr(&password)=&pwd";
run;
proc http
method="POST"
url="https://google.com"
in=input
headerout=headers
out=resp;
debug level=2;
run;
and got this:
100 method="POST" 101 url="https://google.com" 102 in=input 103 headerout=headers 104 out=resp; 105 debug level=2; 106 run; > POST / HTTP/1.1 > User-Agent: SAS/9 > Host: google.com > Accept: */* > Connection: Keep-Alive > Content-Length: 35 > Content-Type: application/x-www-form-urlencoded > > 00007F93DA73E260: 75 73 65 72 6E 61 6D 65 3D 4D 79 4E 61 6D 65 26 username=MyName& > 00007F93DA73E270: 70 61 73 73 77 6F 72 64 3D 4D 79 50 61 73 73 77 password=MyPassw > 00007F93DA73E280: 6F 72 64 ord < HTTP/1.1 405 Method Not Allowed < Allow: GET, HEAD < Date: Fri, 03 Apr 2020 22:01:40 GMT < Content-Type: text/html; charset=UTF-8 < Server: gws < Content-Length: 1589 < X-XSS-Protection: 0 < X-Frame-Options: SAMEORIGIN < Alt-Svc: quic=":443"; ma=2592000; v="46,43",h3-Q050=":443"; ma=2592000,h3-Q049=":443"; ma=2592000,h3-Q048=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,h3-T050=":443"; ma=2592000 <
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.