Я использую топор ios (на веб-сайте клиента) и причал (в промежуточном программном обеспечении)
Очень удобно использовать топор ios .get или ax ios .post ... все все еще будет хорошо, пока я не использую топор ios .delete
Тогда я получаю следующие ошибки при удалении:
В javascript для топора ios
import axios from '../http'
export async function GetAllBooking(){
return await axios.get('/admin/booking').then(respone => {
return respone;
}).catch(e=> {
console.log(e);
});
}
export async function
Delete(id){
return await axios.delete('/admin/booking',{
params:{
id: id
}
}).then(respone=>{
return respone;
}).catch(e=> {
console.log(e);
});
}
В конфиге для топора ios
импорт топора ios из 'топора ios';
axios.defaults.withCredentials=true;
const instance = axios.create({
// .. where we make our configurations
baseURL: 'http://localhost:8000'
});
// Add a request interceptor
axios.interceptors.request.use(function (config) {
// Do something before request is sent
return config;
}, function (error) {
// Do something with request error
return Promise.reject(error);
});
// Add a response interceptor
axios.interceptors.response.use(function (response) {
// Any status code that lie within the range of 2xx cause this function to trigger
// Do something with response data
return response;
}, function (error) {
// Any status codes that falls outside the range of 2xx cause this function to trigger
// Do something with response error
return Promise.reject(error);
});
export default instance;
Что я делаю в пристани при создании doDelete
public class AdminBooking extends HttpServlet{
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{
System.out.println("GET BOOKING - ADMIN ");
try {
resp.addHeader("Access-Control-Allow-Origin", "http://localhost:8080");
resp.addHeader("Access-Control-Allow-Credentials","true");
resp.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE");
HttpSession session=req.getSession(false);
if(session != null ) {
TTransport transport; //1
transport = new TSocket("localhost", 9090); //2
transport.open(); //3
TProtocol protocol = new TBinaryProtocol(transport); //4
connectDBService.Client client = new connectDBService.Client(protocol); //5 Must have in client
List<booking> lstbooking = client.GetBooking();
resp.setContentType("application/json;charset=UTF-8");
ServletOutputStream out = resp.getOutputStream();
Gson gson = new GsonBuilder().create();
JsonArray arr = gson.toJsonTree(lstbooking).getAsJsonArray();
out.print(arr.toString());
transport.close();
}
} catch (TTransportException e) {
e.printStackTrace();
} catch (TException e) {
e.printStackTrace();
}
}
protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{
int id = Integer.parseInt(req.getParameter("id"));
System.out.println("Delete Booking");
try {
resp.addHeader("Access-Control-Allow-Origin", "http://localhost:8080");
resp.addHeader("Access-Control-Allow-Credentials","true");
resp.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE");
resp.setContentType("application/json;charset=UTF-8");
HttpSession session=req.getSession(false);
if(session != null ) {
TTransport transport; //1
transport = new TSocket("localhost",9090); //2
transport.open(); //3
TProtocol protocol = new TBinaryProtocol(transport); //4
connectDBService.Client client = new connectDBService.Client(protocol); //5 Must have in client
int result = client.DeleteBooking(id);
ServletOutputStream out = resp.getOutputStream();
Gson gson = new GsonBuilder().create();
Map<String, Integer> res= new HashMap<>();
res.put("result",result);
JsonObject arr = gson.toJsonTree(res).getAsJsonObject();
out.print(arr.toString());
transport.close();
}
} catch (TTransportException e) {
e.printStackTrace();
} catch (TException e) {
e.printStackTrace();
}
}
}
Скажите, пожалуйста, что не так с моим кодом @@ Я так устал от этого
Спасибо