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
sfdcFanBoysfdcFanBoy 

Webservice Callout failed. Bad Request - Invalid Header.

My webservice callout failed giving the following error.

 

Bad Request - Invalid Header

 

HTTP Error 400. The request has an invalid header name.

 

 

What does it mean by Invalid header?

 

 

Here's my code.  I have used similar code for my other webservices which works fine.  Not sure what is wrong here.  Can anyone please highlight?  Thanks.

 

String username='abc';
String password='abc';

tempuriOrg.BasicHttpBinding stub = new tempuriOrg.BasicHttpBinding();  
stub.timeout_x=120000;
stub.inputHttpHeaders_x = new Map<String, String>();        
Blob headerValue = Blob.valueOf(username + ':' + password);            
String authorizationHeader = 'Basic '+ EncodingUtil.base64Encode(headerValue);                
stub.inputHttpHeaders_x.put('Authorization', authorizationHeader);        
stub.inputHttpHeaders_x.put(username,password);
String response = stub.LoadSalesForceData('0000100005');                                                    

System.debug('NDS Response--------'+response);

 

 

Vinita_SFDCVinita_SFDC

Hello,

 

This code snippet seems correct. This error appears when the request couldn’t be understood, usually because the JSON or XML body contains an error. Please make sure that endpoint has been defined correctly.

 

Also check what response are you receiving, is it throwing any error?

 

 

sfdcFanBoysfdcFanBoy
The response is error too.


System.CalloutException: Web service callout failed: Unexpected element. Parser was expecting element 'http://schemas.xmlsoap.org/soap/envelope/:Envelope' but found ':HTML'
Vinita_SFDCVinita_SFDC

Hello Manish,

 

Usually this error message is produced by a problem of communication with the external webservice.

Try to:
1. Check if external webservice is really available and working.
2. Check if Salesforce's IP addresses are included in whitelist on the firewall of the network where the external wabservice is located.
3. Validate the endpoint address of the webservice.
4. Check if the endpoint's server is enabled as a Remote Site in Salesforce.
5. Remember that web service must be accesible from Internet to a public and valid IP address.