我正在创建一个将xml格式发送到服务器API并以XML格式获取响应的应用程序!问题是有时我得到了所需的输出,有时候没有! 我正在使用transferto api充电
这是我的代码:
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);
}
}
sTS是使用时间戳和Md5创建的唯一键,具体取决于此!一切顺利!但是,当应用程序第一次运行时,它会提供实际输出,然后它就不会!我在这做错了什么! xml如何发送到服务器有什么问题吗?