0

I am creating an application to send xml format to server API and get response in XML format!! The issue is sometime i get the required output and sometime not!! I am using transferto api for recharges

This is my code:

public void testxml() throws ClientProtocolException, IOException{
            String sClientTxID = new SimpleDateFormat("yyyyMMddHHmmssMS").format(new Date());
            String sTS = sClientTxID;
            String md5_string = getKeyedDigest("myusername","mytoken",sTS);
            System.out.println(md5_string);
            String inputXML = "<xml><login>mobeeload</login><key>"+sTS+"</key><md5>"+md5_string+"</md5><action>ping</action></xml>";
             System.out.println(inputXML);
            InputStream in ;
              StringEntity entity = new StringEntity(inputXML, ContentType.create(
                "text/xml", Consts.UTF_8));
              entity.setChunked(true);
              HttpPost httppost = new HttpPost(url);

              httppost.setEntity(entity);

              HttpClient client = HttpClients.createDefault();

              try {
               HttpResponse response = client.execute(httppost);
               System.out.println(response.toString());
               in=response.getEntity().getContent();
               String body = IOUtils.toString(in);
               System.out.println(body);
              } catch (ClientProtocolException e) {
               System.out.println(e);
              } catch (IOException e) {
               System.out.println(e);
              }

        }

The sTS is the unique key creating using timestamp and Md5 depending on that! everything works wells! But when application runs for the first time it gives actual output and then it does not!! What am i doing wrong here! Is there any issues how xml is sending to Server?

  • Can you please try below HttpHeaders headers = new HttpHeaders(); headers.add("header_name", "header_value"); Headers.setContentType(MediaType.APPLICATION_XML); – Pradeep Apr 27 '17 at 11:41
  • http://stackoverflow.com/questions/35461148/how-to-send-xml-post-requests-with-spring-resttemplate – Pradeep Apr 27 '17 at 11:41

0 Answers0