BookmarkSubscribeRSS Feed
Obsidian | Level 7

This mostly a duplicate question that went unanswered. GET requests work fine and var1 and var2 both become SAS variables in the receiving stored process, but POST requests are failing. Here is the sample request that works. Change it to a POST and it fails.


$.ajax({url: '&_THISSESSION&' + '_program=/my_stored_process', 
	type: 'GET',
   	data: { var1: 1, var2: 'somevalue'} ,
	contentType: 'application/json; charset=utf-8',
	success: function(result){

It seems the answer (which was mentioned in the previous thread) is to create a data source and send the stored process properly formatted XML which is painful. But, was wondering if anyone else found a way to get a POST to work. 


And I've actually answered this myself extremely painfully here. Just wondering if this is the only way.



Obsidian | Level 7

Turns out the data line string in the jquery ajax needs to be formatted differently and quite annoyingly the content type needs to be modified as well.


data : 'var1=1234&var2=othername'
contentType : 'application/x-www-form-urlencoded'


Lapis Lazuli | Level 10

The way JQuery handles POST data is a little annoying compared to most other frameworks. It doesn't really do anything with the data you pass it for a POST, expecting you to preformat and urlencode your post body yourself so that it can just append to the request. For GET requests it serialises and encodes the data properly.


There's a little more info on the content-type subject in this post (not sure if you've seen my reply as I wrote it about 5 months after your question). It is somewhat specific to POST requests - simplest explanation I've found is on wikipedia. From the best of my knowledge, it's all to do with the old days when POST requests were used to submit form data, and x-form-www-urlencoded being the only type that allows you send duplicate parameter values (ie. how multiselects were handled in old school forms). SAS expects this contentType and takes advantage of the duplicate params capability with the whole &parameter=firstvalue, &parameter0=2, &parameter1=firstvalue, &parameter2=secondvalue approach. Conversely, multipart/form-data is what you'd use for uploading files, which is very well documented by SAS here, (I assume you know about it but others might not).


To see how our adapter handles this, see here and here.


Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.


Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 2 in conversation