双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

关于XHR的问题,新人很困惑,为什么获取不到报404

qq_28803955 qq_28803955 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

就是这样子,今天突然就获取不到了

这个是后台代码



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地址没有问题
...全文

相关推荐

评论 1
收藏 已收藏
分享
返回顶部
qq_28803955
Java EE 67,535 成员 225,843 内容