function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Masahito AkashiMasahito Akashi 

POST parameters lost, using Continuation Class

I requested callout POST by setting the parameters in the setBody using Continuation Class.
but Parameter is not set in received server.
// Create continuation with a timeout
Continuation con = new Continuation(40);
// Set callback method
con.continuationMethod='processResponse';

// HTTP Request
HttpRequest req = new HttpRequest();
req.setEndpoint(getCalloutURL());
req.setMethod('POST');

// POST Parameters
List<String> params = new List<String>();
params.add('UserId=' + 'test');
params.add('Password=' + 'pass');
req.setBody(String.join(params, '&'));

// Add callout request to continuation
this.requestLabel = con.addHttpRequest(req);

return con;
How should I do it?


 
srlawr uksrlawr uk
I only used continutations myself for the first time a couple of months ago, but that kind of looks alright to me. Are you sure the server isn't recieving the parameters (I know it sounds like a cop out, but various popular server tech logs for getURL and getParams can be crap for stripping urls and missing pertinent data in my experience!) 

Also, as a thought, are you trying to do BASIC auth with your params here? In which case something more like
 
HttpRequest req = new HttpRequest();
req.setEndpoint(getCalloutURL());
req.setMethod('POST');

Blob headerValue = Blob.valueOf('test:pass');
String authorizationHeader = 'BASIC ' + EncodingUtil.base64Encode(headerValue);

req.setHeader('Authorization', authorizationHeader);

Would be what I'd use... (obviously you can tokenize in your data from strings at "test:pass" )
Masahito AkashiMasahito Akashi
Hi.

If I was a simple request, I was able to successfully send a POST parameter.
But it did not receive a POST parameter when transmitting the same content using the Continuation.

The following code works correctly. (But it fails when using the Continuation...)
 
// HTTP Request
HttpRequest req = new HttpRequest();
req.setEndpoint(getCalloutURL());
req.setMethod('POST');

// POST Parameters
List<String> params = new List<String>();
params.add('UserId=' + 'test');
params.add('Password=' + 'pass');
req.setBody(String.join(params, '&'));

// Normal send
Http h = new Http();
HttpResponse res = h.send(req);

system.debug(res.getStatusCode());
system.debug(res.getBody());

This parameter is the example. There are other a lot of options.
This authentication method I think that's nonsense. But is a specification of a third-party Web services.

Thanks.
Masahito AkashiMasahito Akashi
I was succeeded by adding the content-type header.
HttpRequest req = new HttpRequest();
req.setEndpoint(getCalloutURL());
req.setMethod('POST');
req.setHeader('Content-Type', 'application/x-www-form-urlencoded');
I did not know the problems in Salesforce or OtherServer.
Thanks.