+ Start a Discussion

Post request

Hello there,


I need to set an http request with the setMethod('POST'); i already did a few http request with the GET method and it was working pretty well, but my POST request doesn't work.


I was thinking that i just need to change the setMethod parameter, after a few research i saw a way to put the parameters

using setBody but isn't working. I got error from my server as "Invalid parameters"


Here some code sample:


    	Http http = new Http();
        HttpRequest req = new HttpRequest(); 
        HttpResponse res = new HttpResponse();


And i tried to pust the parameters following this way:


req.setBody(EncodingUtil.urlEncode(string.valueof(line.Id_uad__c), 'UTF-8')+'|'+ EncodingUtil.urlEncode(string.valueof(line.Quantity.setscale(0)), 'UTF-8')
				+ '|' +EncodingUtil.urlEncode(string.valueof(line.Quantity.setscale(0)), 'UTF-8') + EncodingUtil.urlEncode(line.MPN__c , 'UTF-8') + '|' +
				EncodingUtil.urlEncode(string.valueof(line.UnitPrice) , 'UTF-8'));


Does anyone can help me?