0

I am sending XMLHttpRequest using apex but unfortunately below Error is Coming

Error Bad Request Your browser sent a request that this server could not understand

Here is my code.

public class A99AcresIntegration{

     public static void makeGetCallout(){
         String User_name = 'XXXXXXXX';
         String Pwd = 'XXXXXXXXX';
         DateTime Startdate = system.now()- 2;
         DateTime EndDate =   system.now();
         Http http = New Http();
         HttpRequest request = new HttpRequest();
    request.setEndpoint('http://www.99acres.com/99api/v1/getmy99Response/OeAuXClO43hwseaXEQ/uid/<?xml  version=1.0+?><query><user_name> '+User_name+'</user_name><pswd>'+Pwd+'</pswd><start_date>'+Startdate+'</start_date><end_date>'+EndDate+'</end_date></query>'); 

         request.setMethod('POST');
         request.setHeader('Content-Type','Text/xml');
        HttpResponse response = http.send(request);           
     }
} 

Please give solution for this question.

1

I believe you need to put body in body

public static void makeGetCallout(){
     String User_name = 'XXXXXXXX';
     String Pwd = 'XXXXXXXXX';
     DateTime Startdate = system.now()- 2;
     DateTime EndDate =   system.now();
     Http http = New Http();
     HttpRequest request = new HttpRequest();
request.setEndpoint('http://www.99acres.com/99api/v1/getmy99Response/OeAuXClO43hwseaXEQ/uid/'); 
request.setBody('<?xml  version=1.0+?><query><user_name> '+User_name+'</user_name><pswd>'+Pwd+'</pswd><start_date>'+Startdate+'</start_date><end_date>'+EndDate+'</end_date></query>');

     request.setMethod('POST');
     request.setHeader('Content-Type','Text/xml');
    HttpResponse response = http.send(request);           
     }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.