我遇到了下面描述的问题
我正在使用 chrome 来测试由 java 应用程序提供的 api,它是一个 spring boot 应用程序,它调用一个 dll 应用程序。当我使用 chrome 从 html 文件发送请求时,浏览器一直卡住,直到我关闭spring boot app 虽然 java 应用程序代码运行到结束。
除了microsoft edge,firefox也出现这个问题,这是为什么?
谁能告诉我 chrome 向后台服务发送请求的过程以及为什么 edge 正常。非常感谢
以下是源码:
java代码:
@RestController
@RequestMapping("request")
public class RequestController {
@RequestMapping("do")
public ResultBean<Map> request(@RequestBody Map<String,Object> body){
Map<String,Object> result;
try {
String json =
SiInterface.call(body.get("input").toString());
result = JSONObject.parseObject(json, Map.class);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
result = new HashMap<>();
}
return new ResultBean<Map>(result);
}
}
public static String call(String input) throws
UnsupportedEncodingException {
int code= SiInterface.getInstance().INIT(new byte[2000000]);
input = new String(input.getBytes("iso-8859-1"), "gbk");
Memory inMemery = new Memory(input.length());
inMemery.write(0, input.getBytes(), 0, input.length());
byte[] outMemery = new byte[2000000];
code= SiInterface.getInstance().BUSINESS_HANDLE(input, outMemery);
String outStr=null;
try {
outStr = new String(outMemery,"gbk");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
StringBuilder sb=new StringBuilder();
for(int i=0;i<outStr.length();i++){
if((int)outStr.charAt(i)>0){
sb.append(outStr.charAt(i));
}
}
return sb.toString();
}
javascript:
//var obj = document.getElementById("SiInterface");
var url = "http://127.0.0.1:18090/request/do";
var INPUT = document.getElementById("INPUT").value;
var inJson = {
"input": INPUT
};
// inJson=JSON.stringify(INPUT)
console.log(JSON.stringify(inJson));
$.ajax({
url : url,
type : "POST",
contentType:"application/json",
dataType : "json",
async : true,
data : JSON.stringify(inJson),
success : function(data) {
// 成功
document.getElementById("OUTPUT").value = JSON.stringify(data);
}
});
/*
console.log(INPUT);
var OutPut = obj.SendRequest(url ,INPUT);*/