Http http = new Http();
HttpRequest req = new HttpRequest();
req.setHeader('Content-Type', 'application/xml'); 
HttpResponse res = http.send(req);
string xmlresponse=res.getBody();

I am getting data and it is working fine but i need to send success message and some data to same url as i received data from server.

Is there any way to do that

Please help me out.

  • Same way like you're doing the first call I believe. Another post request after you receive the data? – Boris Bachovski Jun 19 '14 at 7:10
  • Yes after receiving the data i need to send response data as i received their data. – Sunny Jun 19 '14 at 8:29

You can do that by sending response to the application making the call to your web service. Here is an example:

    RestResponse res = RestContext.response;
    res.statusCode = 200; //Signifies OK
    jsonResponse = '{"response": {"Data": "Value", "Data": "Value"}}';
    res.responseBody = blob.valueOf(jsonResponse);

Add the above code after the point when you have received and saved the data incoming from the web service.

Let me know if it works for you.

Happy Coding!!

  • I placed the code and make it as return type string for that method, and i need to send xml format like xml format , can u help me.... The response is coming in "data we sent" format in their response – Sunny Jun 19 '14 at 9:10
  • You need not set the return type to string , the above code will send the response in JSON. I'm sorry I did not get the the issue above can you elaborate a little. – Mohd Nadeem Shaikh Jun 19 '14 at 9:21
  • Actually when we sending the response in the other side we are getting the response data enclosed with "" symbols. – Sunny Jun 19 '14 at 9:37
  • That's right, it is in JSON. If let's say the other system is .net based you can use inbuilt classes to parse the above response in to a Name = value formal like normal objects and data types. What you now need is to parse the JSON response in the desired object type. – Mohd Nadeem Shaikh Jun 19 '14 at 11:35

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.