I need to do a post to a server to retrieve a token. Currently I have it set up to use content type:x-www-form-urlencoded in the header but am unfamiliar with how to create the form body. I tried creating a JSON payload but it fails with bad request. Any information on how I can get this to work, would be greatly appreciated.
Here is my code for the header and json body:
Header:
@Headers =
'Cache-Control: no-cache' + @CrLf +
'content-type: x-www-form-urlencoded' + @Crlf +
'accept: */*' + @Crlf;
Body:
yajl_beginObj();
yajl_addchar('grant_type':'client_credentials');
yajl_addchar('client_id': %Trim(MMid));
yajl_addchar('client_secret': %Trim(MMSecret));
yajl_endObj();
%len(@jsonData) = @JSON_BUF_SIZE;
@rc = yajl_copyBuf(0
: %addr(@jsonData: *data)
: @JSON_BUF_SIZE
: @len );
%len(@jsonData) = @len;
yajl_savebuf(%Trim(@AuthFile): @Error);
http_debug(*On:'/mastery/authdebug.txt');
http_setccsids(1208:0);
Http_xproc(HTTP_POINT_ADDL_HEADER
: %paddr($Add_Headers));
@rc = Http_url_post(%Trim(@Uri)
: %Addr(@jsondata) + 2
: %Len(%Trim(@jsondata))
: @AuthFile
: 15
: Http_UserAgent
: 'x-www-form-urlencoded ');
Here is my code for the header and json body:
Header:
@Headers =
'Cache-Control: no-cache' + @CrLf +
'content-type: x-www-form-urlencoded' + @Crlf +
'accept: */*' + @Crlf;
Body:
yajl_beginObj();
yajl_addchar('grant_type':'client_credentials');
yajl_addchar('client_id': %Trim(MMid));
yajl_addchar('client_secret': %Trim(MMSecret));
yajl_endObj();
%len(@jsonData) = @JSON_BUF_SIZE;
@rc = yajl_copyBuf(0
: %addr(@jsonData: *data)
: @JSON_BUF_SIZE
: @len );
%len(@jsonData) = @len;
yajl_savebuf(%Trim(@AuthFile): @Error);
http_debug(*On:'/mastery/authdebug.txt');
http_setccsids(1208:0);
Http_xproc(HTTP_POINT_ADDL_HEADER
: %paddr($Add_Headers));
@rc = Http_url_post(%Trim(@Uri)
: %Addr(@jsondata) + 2
: %Len(%Trim(@jsondata))
: @AuthFile
: 15
: Http_UserAgent
: 'x-www-form-urlencoded ');
Comment