我正在尝试POST提交XML字符串到Manage Engine REST API(文档here)。我使用%http宏(Garth Helf)在SAS中执行此操作。
我发送/接收的标题如下(为简洁起见,XML非urlencoded):
>>> HTTP Request:
POST /sdpapi/request?OPERATION_NAME=ADD_REQUEST&TECHNICIAN_KEY=666-666-666 HTTP/1.1
Host: DEV-SDPLUS
Content-Length: 101
Connection: Close
&INPUT_TYPE=<?xml version='1.0'?><Operation><Details> <subject>Test</subject></Details></Operation>
<<< HTTP Response:
HTTP/1.1 200 OK
Set-Cookie: JSESSIONID=FFE99B5C995093265402E5F54A09A056; Path=/
X-Powered-By: Servlet 2.4; Tomcat-5.0.28/JBoss-3.2.6 (build: CVSTag=JBoss_3_2_6 date=200410140106)
Content-Type: text/xml;charset=UTF-8
Content-Length: 135
Date: Mon, 23 Mar 2015 12:00:59 GMT
Server: Apache-Coyote/1.1
Connection: close
<operation name="ADD_REQUEST"><result><status>Failed</status><message>No input data for creating request</message></result></operation>
通过url提交时,XML工作正常(返回workorderid):
proc http out=out method="POST"
url="&MANAGE_ENGINE_URL/request?OPERATION_NAME=ADD_REQUEST%str(&)TECHNICIAN_KEY=&MANAGE_ENGINE_API_KEY%str(&)INPUT_DATA=%sysfunc(urlencode(&xml))"
; run;
但是,此方法会因URL为512个字符及以上而失效。
有没有人有使用SAS向网络服务提交长XML字符串的经验?
编辑:proc http(512 chars)限制似乎与SAS相关,因为我可以使用CURL通过URL成功提交更长的XML字符串。但是,如果可能的话,我们希望避免在服务器上使用命令行(x curl)..
答案 0 :(得分:4)
html
过程可以从fileref
读取POST参数。可以在user guide中找到一个示例。这样您就可以将url
选项保持为可接受的长度。
一个粗略的例子是
/* Create fileref to store POST parameters */
filename in "/path/to/files/in.txt";
/* Create fileref to store http response */
filename out temp;
/* Write parameters to file */
data _null_;
file in;
input;
put _infile_;
datalines4;
&INPUT_DATA=<?xml version='1.0'?><Operation><Details> <subject>Test</subject></Details></Operation>
;;;;
run
/* Run the request */
proc http
in = in
out = out
method = "POST"
url = "&MANAGE_ENGINE_URL/request?OPERATION_NAME=ADD_REQUEST%str(&)TECHNICIAN_KEY=&MANAGE_ENGINE_API_KEY";
run;