You need to sign in to do that
Don't have an account?
Kaushik Muhuri 15
http request
Is there any specific reason for the following error:
Status=Length Required, StatusCode=411
I am using http post in apex.
Status=Length Required, StatusCode=411
I am using http post in apex.
something like req.setHeader('Content-Length', '4096'); But it depends on the length of your request
Hope it helps, if it does please mark as correct, it may help others
If i am being helpful please like or mark as correct, if not please send full request but that should do it
string url = 'https://............./';
string key = '*************************';
string mobile = '**********';
string userid = '********';
// string start_date = System.now().addHours(-1).format('dd-MMM-yyyy HH:MM:ss').replace(' ','%20');
string start_date = '14-MAY-2020%2015:00';
System.debug('===start_date==='+start_date);
// string to_date = System.now().format('dd-MMM-yyyy HH:MM:ss').replace(' ','%20');
string to_date = '14-MAY-2020%2017:00';
System.debug('===to_date==='+to_date);
string endpoint = 'GLUSR_MOBILE/'+mobile +'/GLUSR_MOBILE_KEY/'+key+'/Start_Time/'+start_date+'/End_Time/'+to_date+'/';
System.debug('>>>> endpoint >>>>>' + endpoint);
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setHeader( 'Content-Type', 'application/json;charset=utf-8' );
request.setEndpoint(url+endpoint);
request.setMethod('POST');
request.setHeader('Content-Length', '0');
System.debug('>>>> Request>>>>>' + request);
HttpResponse response = http.send(request);
Another question, the service you are trying to get has a "get" endpoint that you could try?
The content lenght in 0 should have fixed this mistake, you could try values other than 0 but the error should not be 411.
The other question would be, does this api have a get call you could try instead of this post?
Please mark the first comment as correct as it is the answer for this question, I have no problem to keep answering you but this is solved with that solution
I am experiencing a new problem.The same endpoint when run from Postman gives expected result.
But with Apex HTTP Request I am getting : Status=Service Unavailable, StatusCode=503.
I know that there is no chances of the service being unavailable.
If that is not the case then the server may be down for maintenance but if the url and everything is right on your side the issue is on the other end.
That is what the 503 error means, the only thing from your end could be the remote site settings.
Good luck, and if it helps please put as correct or give like to the answers that helped you. It is encouragement for us that use our time to help on this community.
If body is empty, try add:
request.setBody('{}');
if still not working, try add:
request.setHeader('Content-Length', '0');