You need to sign in to do that
Don't have an account?
LilFirecracker
Http Response defaults Content-Type to text/plain, not application/json
I have a HTTP Request that sends out an endpoint to an Azure function. I've added the endpoint url to Remote Site Settings. When I send the request in Postman, I get a 200 OK status. When I send this request from Salesforce, I get a 400 Bad Request.
I have tried to set Content-Type and Accept to application/json but keep getting the 400 error and the response header as text/plain (see debug log).
Why isn't the response header Content-Type set to application/json? Is there any other way to make sure the response is being returned as application/json? This is my first time with an http request so if I'm missing something or if you have any ideas on a fix, I would be super grateful!
I have tried to set Content-Type and Accept to application/json but keep getting the 400 error and the response header as text/plain (see debug log).
Why isn't the response header Content-Type set to application/json? Is there any other way to make sure the response is being returned as application/json? This is my first time with an http request so if I'm missing something or if you have any ideas on a fix, I would be super grateful!
public static Boolean mergeTest(String masterId, String followerId){ JSONGenerator gen = JSON.createGenerator(true); gen.writeStartObject(); gen.writeStringField('is_sandbox', String.valueOf(Utils.runningInASandbox())); gen.writeStringField('master',masterId); gen.writeStringField('follower',followerId); gen.writeEndObject(); String jsonS = gen.getAsString(); String endpoint = 'https://xxxxxxxxxxx.azurewebsites.net/api/FunctionName?code=defaultFunctionKey=='; HttpRequest req = new HttpRequest(); req.setEndpoint(endpoint); req.setMethod('POST'); req.setbody(jsonS); req.setHeader('x-functions-key', 'masterHostKey'); req.setHeader('Content-Type','application/json'); req.setHeader('Accept', 'application/json'); Http http = new Http(); req.setTimeout(120000); HTTPResponse response; if (!Test.isRunningTest()){ try{ response = http.send(req); if (response.getStatusCode() == 500) { return False; } } catch (System.Exception e){ System.debug('Callout exception error: '+e); } } return True; }
One other thing I noticed in postman...the response headers tab shows the same as the debug logs in Salesforce. Could the 400 error be related to something else? Where/how can I get the curl from Salesforce?
Also remove the accept part from the Header?
Just for testing, try to hard code the values and check how you get it.
I did run into 'System CalloutException: Read timed out' when using a larger data set. Since I already setTimeout to the max 120000, is the only other option to avoid this error to use a smaller data set or would you have any other suggestion to try?
Regarding Timeout setting, you are ok with that.
Would you be kind to mark my above comments as best if that helped narrow down your issue for others?