就是这样子,今天突然就获取不到了
这个是后台代码
public static String doGet(String meraccount,String sale_count)
throws ServletException, IOException {
StringBuffer resultBuffer = new StringBuffer();
try {
JSONObject obj = new JSONObject();
obj.put("meraccount",meraccount);
obj.put("method", "queryRstation");
obj.put("v", "1.0");
obj.put("sale_count", sale_count);
obj.put("timestamp", System.currentTimeMillis());
String param_key = encrypt(
URLEncoder.encode(obj.toString(), "UTF-8"),
PUBLICKEY);
String secret_key = URLEncoder.encode(
MD5(paramSort(obj)), "UTF-8");
ClientResource client = new ClientResource(
"http://222.184.1.86:8880/queryService/1.0/hts/queryRstation?param_key="
+ param_key + "&secret_key=" + secret_key
+ "&sale_count=3208000993005");
Representation representation = client.get();
InputStream is = representation.getStream();
resultBuffer.append(InputStreamTOString(is));
} catch (Exception e) {
e.printStackTrace();
}
return resultBuffer.toString();
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/json");
response.setCharacterEncoding("UTF-8");
String meraccount = request.getParameter("meraccount");
String sale_count = request.getParameter("sale_count");
PrintWriter out = response.getWriter();
String jieguo =doGet(meraccount, sale_count);
out.print(jieguo);
System.out.println(jieguo);
}
这个是前台获取的
var shanghu = $("#CardNo").val();
var shoupiao = $("#PageNum").val();
var data = {
"meraccount":shanghu,
"sale_count": shoupiao,
}
var url ="servlet/BusServlet";//servlet路径
$.post(url,data,function(bbb){
var hhh = bbb;
for(var o in hhh.result){
alert(hhh.result[o].dep_station_name);
}
},"json");
再三检查过了 URL地址没有问题