Question & Answer
Question
Support of web form in API Connect : POST HTTP requests with "application/x-www-form-urlencoded" ?and "multipart/form-data" content types
Answer
Author: Volodymyr Sitarchuk
Reviewer: Werner Tod
The "application/x-www-form-urlencoded" as well as the "multipart/form-data" content types are not supported by IBM API Connect yet.
To be exact, there are no parsers for them included in the product. IBM API Connect can only parse XML and JSON data from a request body.
To work around this limitation, a custom parser can be built.
For web forms posting data with a content type of "application/x-www-form-urlencoded",
you can drop a GatewayScript component into the API assembly with JavaScript that
extracts the raw data from the request body (apim.getvariable("request.body").item(0))
and then parses it.
In general, the basic structure of the parser looks as follows:
var bodyAsBlob = apim.getvariable("request.body").item(0);
var bodyAsString = bodyAsBlob.toBuffer().toString();
var parameters = bodyAsString.split("&");
for (var i = 0 ; i < parameters.length ; i++) {
var parameter = parameters[i].split('=');
var parameterName = decodeURIComponent(parameter[0]);
var parameterValue = decodeURIComponent(parameter[1]);
}
There is a RFE (enhancement request) for adding the support of the "application/x-www-form-urlencoded" to IBM API Connect:
https://www.ibm.com/developerworks/rfe/execute?use_case=viewRfe&CR_ID=91616
but there is no RFE for "multipart/form-data" support yet.
Reviewer: Werner Tod
The "application/x-www-form-urlencoded" as well as the "multipart/form-data" content types are not supported by IBM API Connect yet.
To be exact, there are no parsers for them included in the product. IBM API Connect can only parse XML and JSON data from a request body.
To work around this limitation, a custom parser can be built.
For web forms posting data with a content type of "application/x-www-form-urlencoded",
you can drop a GatewayScript component into the API assembly with JavaScript that
extracts the raw data from the request body (apim.getvariable("request.body").item(0))
and then parses it.
In general, the basic structure of the parser looks as follows:
var bodyAsBlob = apim.getvariable("request.body").item(0);
var bodyAsString = bodyAsBlob.toBuffer().toString();
var parameters = bodyAsString.split("&");
for (var i = 0 ; i < parameters.length ; i++) {
var parameter = parameters[i].split('=');
var parameterName = decodeURIComponent(parameter[0]);
var parameterValue = decodeURIComponent(parameter[1]);
}
There is a RFE (enhancement request) for adding the support of the "application/x-www-form-urlencoded" to IBM API Connect:
https://www.ibm.com/developerworks/rfe/execute?use_case=viewRfe&CR_ID=91616
but there is no RFE for "multipart/form-data" support yet.
[{"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Product":{"code":"SSQTW3","label":"IBM On Demand Consulting for Hybrid Cloud"},"Component":"","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"All Versions","Edition":"","Line of Business":{"code":"","label":""}}]
Was this topic helpful?
Document Information
More support for:
IBM On Demand Consulting for Hybrid Cloud
Software version:
All Versions
Document number:
778875
Modified date:
22 March 2019
UID
ibm10778875
Manage My Notification Subscriptions