JAVA中怎么通过Http Post的方式调用webservice接口
接口地址为:http://121.199.174.72:30000/PubService.svc/QuerySaleOrder测试参数为:v=1.0&sign=&mess...
接口地址为:http://121.199.174.72:30000/PubService.svc/QuerySaleOrder
测试参数为:v=1.0&sign=&message={
"starttime": "2017-4-1 00:00:00",
"endtime": "2017-9-1 00:00:00",
"shopcode":"liur",
"ordercodes": null,
"pagesize": 0,
"pagenum": 0,
"IsInvoiceAudit": 1,
"startinvoiceaudittime": "2017-1-1 00:00:00",
"endinvoiceaudittime": "2017-9-1 00:00:00"
}
在线等 ,很着急,谢谢,最好是有代码 展开
测试参数为:v=1.0&sign=&message={
"starttime": "2017-4-1 00:00:00",
"endtime": "2017-9-1 00:00:00",
"shopcode":"liur",
"ordercodes": null,
"pagesize": 0,
"pagenum": 0,
"IsInvoiceAudit": 1,
"startinvoiceaudittime": "2017-1-1 00:00:00",
"endinvoiceaudittime": "2017-9-1 00:00:00"
}
在线等 ,很着急,谢谢,最好是有代码 展开
展开全部
public static String POST(String url, String param) {
OutputStreamWriter out = null;
BufferedReader in = null;
OutputStream os = null;
InputStream is = null;
InputStreamReader isr = null;
String result = "";
try {
URL realUrl = new URL(url);
URLConnection conn = realUrl.openConnection();
conn.setRequestProperty("accept", "*/*");
conn.setRequestProperty("connection", "Keep-Alive");
conn.setDoOutput(true);
conn.setDoInput(true);
os=conn.getOutputStream();
os.write(param);
is = conn.getInputStream();
isr = new InputStreamReader(is, "utf-8");
in = new BufferedReader(isr);
String line;
while ((line = in.readLine()) != null) {
result += line;
}
} catch (Exception e) {
e.printStackTrace();
}
finally {
try {
if (out != null) {
out.close();
}
if (in != null) {
in.close();
}
if(os!=null){
os.close();
}
if(is!=null){
is.close();
}
if(isr!=null){
isr.close();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
return result;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询