Hi,
I am trying to make a get request which had query parameter and the parameter value has special characters but when i pass it to proc http url parameter the special character are being missread and the value is not being supplied correctly to the service
My url looks like this
http://myservice?name=abc+pqr&xyz
proc http
url="http://myservice?name=abc+pqr&xyz"
method=GET
ct="application/json"
in=input
out=resp
headerout=headout;
run;
but the value is going as abc pqr. I tried url encoding also but it dosent work for + and & symbols.
Is there a way to encode urls when passing them to proc http
I think that your URL should work as-is with PROC HTTP. Can you tell us what version of SAS you're using? PROC HTTP has seen many improvements in SAS 9.4.
The + symbol in a URL is translated to whitespace -- that's by design. If you need the + as part of your data, encode it as %2B.
Try your test with the free service httbin.org and see if it echos back what you expect.
%macro echoResp(fn=);
data _null_;
infile &fn;
input;
put _infile_;
run;
%mend;
filename resp temp;
proc http
method='GET'
url='https://httpbin.org/anything?name=abc+pqr&xyz'
out=resp;
run;
%echoResp(fn=resp);
/*
returns:
"args": {
"name": "abc pqr",
"xyz": ""
}
*/
/* encoded plus symbol */
proc http
method='GET'
url='https://httpbin.org/anything?name=abc%2Bpqr&xyz'
out=resp;
run;
%echoResp(fn=resp);
/*
returns:
"args": {
"name": "abc+pqr",
"xyz": ""
},
*/
I am using SASv9.04.01M2P07232014
Great! Then try the test program I shared -- should reveal what you need.
Thanks.. it works with encoded string..
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.