You need to sign in to do that
Don't have an account?
Raghu Pedabba
http Post Help
Dear Gurus,
I need to make POST request.
This is the JSON format for POST
{"products":[{"id":1,"quantity":1}],"desc":"infomation"}
*
Blob headerValue = Blob.valueOf(username + ':' + password);
String authorizationHeader = 'Basic ' + EncodingUtil.base64Encode(headerValue);
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('http://*******:*****/prod/');
request.setMethod('POST');
request.setHeader('Authorization', authorizationHeader);
request.setHeader('Content-Type', 'application/json;charset=UTF-8');
request.setBody('{"products":[{"id":1,"quantity":1}],"user_id":"user11"}');
HttpResponse response = http.send(request);
//if (response.getStatusCode() != 201) {
// System.debug('The status code returned was not expected: ' +
// response.getStatusCode() + ' ' + response.getStatus());
//} else {
System.debug(response.getBody());
This works well.But I want to replace id and quantity with Integar variable.
Please guide me.
Thanks,
Raghu
I need to make POST request.
This is the JSON format for POST
{"products":[{"id":1,"quantity":1}],"desc":"infomation"}
*
Blob headerValue = Blob.valueOf(username + ':' + password);
String authorizationHeader = 'Basic ' + EncodingUtil.base64Encode(headerValue);
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('http://*******:*****/prod/');
request.setMethod('POST');
request.setHeader('Authorization', authorizationHeader);
request.setHeader('Content-Type', 'application/json;charset=UTF-8');
request.setBody('{"products":[{"id":1,"quantity":1}],"user_id":"user11"}');
HttpResponse response = http.send(request);
//if (response.getStatusCode() != 201) {
// System.debug('The status code returned was not expected: ' +
// response.getStatusCode() + ' ' + response.getStatus());
//} else {
System.debug(response.getBody());
This works well.But I want to replace id and quantity with Integar variable.
Please guide me.
Thanks,
Raghu
All Answers