You need to sign in to do that
Don't have an account?
Damien_2
Error Response from HttpRequest
I keep getting the following error code when making my call:
System.HttpResponse[Status=Length Required, StatusCode=411]
I have the Http Request working using the google chrome plugin called 'Dev HTTP Client', but it does not work using the same values in Salesforce. My code that executes the callout looks like:
private void sendNotification() { HttpRequest req = new HttpRequest(); HttpResponse res = new HttpResponse(); Http http = new Http(); String tempPt = 'some valid url'; req.setEndpoint(tempPt);// + '?client_token='+ token + '&client_secret=' + secret); req.setHeader('Cache-Control', 'no-cache'); req.setHeader('Content-Length', '512');//I've tried various values here req.setMethod('GET'); req.setCompressed(true); try { res = http.send(req); System.debug('res = ' + res); ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, '' + res)); } catch(System.CalloutException e) { System.debug('Callout error: '+ e); System.debug(res.toString()); ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, '' + e)); } }
That seems like an erroneous error from the server, but ... you should not set Content-Length unless you are providing a body (which normally occurs only with a POST request). Since you never call HttpRequest.setBody(), Content-Length must not be specified.
Edit: I should have mentioned that the server should have returned a 400 Bad Request error, not a 411 Length Required error. I think they might be using a custom script.
Edit Again: If you do set body, make sure that Content-Length is bodyText.length(), where bodyText is the final encoded form of the POST content (including character or URL encoding, as required).
Yea, originally I did NOT specify a Content-Length, but the chrome plugin I'm using does for the Get request, and when I googled what the issue was that was one of the responses I found according to that error.
I understand that a lot of code is protected as Intellectual Property, so I can understand that you don't want to post the actual code you're using here (this is obviously redacted code), but I think more information is really necessary. If you'd like to PM me your original code attempt that was failing with the original error, I can try and troubleshoot it with you. Effective troubleshooting will require someone knowing what service you're connecting to, what the original code was, and what the original response was. You can still redact the client token and client secret parameters, of course; nobody would ask you to expose your authentication unless it were absolutely necessary, and I suspect that's not the case here.
The service I'm working with actually doesn't require authentication. Before I begin working with the authentication services, I planned on getting the non-authenticated ones working. I could prob give u the URl since it is technically a public URL.
EDIT: http://api.dol.gov/V1/FORMS/$metadata
Hmmmm If I remove
I get a different error though....
Which API are you specificially trying to access? I'm going to check the docs and run a couple quick tests.
There's something nefarious going on here. I'm able to access the API you've mentioned thusly:
And yet the same URL is perfectly failing. So far I've tried disabling compression, making sure it's HTTP only, disabling SSL security, everything, and it's just 400 every time. I'm going to set my web server to log incoming requests and see if I can locate headers that might be halting the process. I have a feeling there's some header specified not mentioned in the docs that salesforce.com is sending by default which is causing grief.
Very possible. Thanks for all the time you already put into it so far!