Jeg har følgende CURL kommando jeg gerne vil have lavet om til PROC HTTP - og jeg er kommet noget af vejen. Det der mangler er selve transporten af (i dette tilfælde) XLSX filen.
CURL -X POST -F "data=@F:\SASNykredit\CURL\CURLJMICTEST2.xlsx" -F publishdate=2018-10-30 -F unpublish=2018-11-22 -F title="JMIC TEST 2018-10-30" -F category="Funktionsliste" https://ptsv2.com/t/kommunikationsplatform/post
Foreløbig er jeg i SAS nået til:
filename req temp;
filename resp temp;
data _null_;
file req termstr=CRLF;
put "-F 'data=@F:\SASNykredit\CURL\CURLJMICTEST2.xlsx' ";
put '-F publishdate=2018-10-30 ';
put '-F unpublish=2018-11-22 ';
put '-F title="JMIC TEST 2018-10-30" ';
put '-F category="Funktionsliste" ';
run;
proc http
URL="https://ptsv2.com/t/kommunikationsplatform/post"
METHOD="POST"
in=req
out=resp;
run;
men som nævnt så bliver XLSX filen ikke overført. Jeg har brug for at flere forskellige filformater kan overføres (pdf, xlsx, docx etc.)
Er der nogen der kan hjælpe og lede mig lidt på vej?
The above suggestion is not quite what I needed - but on the other hand, I wasn't specific enough in my description of my needs.
I need the XLSX file (and other filetypes) to be posted to the URL in a binary(?) format - exactly as the cURL command does.
It looks like the HTTP procedure can't handle this directly, so you need some kind of "pre-burner". A datastep?
I have looked at this post:
But it seems that the final solution has not yet come in this post. But is this the path to follow?
This code works in my case. The challenge is to find out how the Content-Type and Content-Disposition statements should look like - seems like this is different between URLs and depends on the API.
I didn't get much help from CURL parameters (should be possible, but I was not able to figure out how), but going through (=debugging) a (rather complicated) VBA script I was able to find the correct syntax for the C-D and C-T for this URL/API.
Feel free to copy
**********************************************************
filename req "F:\SASNykredit\CURL-HTTP\HTTP trial\Datafiler\request.txt";
filename resp "F:\SASNykredit\CURL_HTTP\HTTP trial\Datafiler\response.txt";
filename binfile "F:\SASNykredit\CURL-HTTP\HTTP trial\Datafiler\testdata.xlsx";
%let _boundary=<a valid boundary string>;
%let _cat=Testliste;
%let _publdate=%sysfunc(today(), yymmddd10.);
%let _unpubldate=%sysfunc(intnx(MONTH,%sysfunc(today(),8.),12,S),yymmddd10.);
%let _binname=%scan(%sysfunc(pathname(binfile)),-1,'\');
%let _title=%upcase(&sysuserid) TEST &_publdate.;
%put &=_boundary &=_cat &=_publdate &=_unpubldate &=_title &=_binname;
/*** Get the RC from PROC HTTP ***/
%macro prochttp_check_return(_exp_code);
%if %symexist(SYS_PROCHTTP_STATUS_CODE) ne 1 %then
%do;
%put ERROR: Expected &_exp_code., but a response was not received from the HTTP Procedure;
%end;
%else
%do;
%if &SYS_PROCHTTP_STATUS_CODE. ne &_exp_code. %then
%do;
%put ERROR: Expected &_exp_code., but received &SYS_PROCHTTP_STATUS_CODE.;
%put &SYS_PROCHTTP_STATUS_PHRASE.;
%end;
%else
%do;
%put NOTE: Alt i orden, forventet returkode: &SYS_PROCHTTP_STATUS_CODE. &SYS_PROCHTTP_STATUS_PHRASE.;
%end;
%end;
%mend prochttp_check_return;
/*** Set up MULTIPART-FORM data ***/
data _null_;
file req termstr=CRLF;
put "--&_boundary.";
put 'Content-Disposition: form-data; name="publish"';
put;
put "&_publdate";
put "--&_boundary.";
put 'Content-Disposition: form-data; name="unpublish"';
put;
put "&_unpubldate";
put "--&_boundary.";
put 'Content-Disposition: form-data; name="category"';
put;
put "&_cat";
put "--&_boundary.";
put 'Content-Disposition: form-data; name="title"';
put;
put "&_title";
put "--&_boundary.";
put 'Content-Disposition: form-data; name="uploadfile"; filename='"&_binname.";
put 'Content-Type: application/octet-stream';
put;
%_run(w);
/*** Add the binary file ***/
data _null_;
file req mod recfm=n;
infile binfile recfm=n;
input c $CHAR1.;
put c $CHAR1. @@;
%_run(w);
/*** Wrap it up ***/
data _null_;
file req mod termstr=CRLF;
put / "--&_boundary.--";
%_run(w);
/*** Calling HTTP ***/
proc http
URL="https://ptsv2.com/t/kommunikationsplatform/post"
METHOD="POST"
CT="multipart/form-data; boundary=&_boundary"
in=req
out=resp;
*DEBUG Level=1;
run;
/*** RCs from PROC HTTP ***/
%put &=sys_prochttp_status_code.;
%put &=sys_prochttp_status_phrase.;
/*** Checking the expected RC ***/
%prochttp_check_return(200);
/*** Finishing ***/
filename req clear;
filename resp clear;
filename binfile clear;
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.