java url 返回值_java提交url后返回值怎么取
展開(kāi)全部
我給樓主一個(gè)小的例子,服務(wù)62616964757a686964616fe4b893e5b19e31333332643935端負(fù)責(zé)接收請(qǐng)求,并且返回“0|提交成功|70.00”,客戶端負(fù)責(zé)提交并且接收返回的數(shù)據(jù)。
服務(wù)端:public?void?doPost(HttpServletRequest?request,?HttpServletResponse?response)throws?ServletException{
response.getWriter().write("0|提交成功|70.00");
}
客戶端:public?boolean?sendFileToRemoteServer()?{
HttpClient?httpClient?=?new?HttpClient();
PostMethod?postMethod?=?new?PostMethod(remote_server_url);
Part[]?params?=?new?Part[1];
if?(f.exists())?{
try?{
params[0]?=?new?StringPart("dest_path",?dest_path,?"GBK");
postMethod.getParams().setContentCharset("GBK");
MultipartRequestEntity?mrp?=?new?MultipartRequestEntity(params,
postMethod.getParams());
postMethod.setRequestEntity(mrp);
httpClient.executeMethod(postMethod);
String?result?=?postMethod.getResponseBodyAsString();
}?catch?(Exception?e)?{
e.printStackTrace();
return?false;
}?finally?{
postMethod.releaseConnection();
}
}?else?{
return?false;
}
}
String result = postMethod.getResponseBodyAsString();就是獲取返回的數(shù)據(jù)的。
總結(jié)
以上是生活随笔為你收集整理的java url 返回值_java提交url后返回值怎么取的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 福州大学java期末试卷2012_福州大
- 下一篇: java遍历集合元素_遍历java集合元