lundi 1 avril 2019

how to fix error 404 in angular 7 even tho the URL is correct

I am trying to send a post request to my java Rest server and it works fine with 10 URLs but now for some reason i am getting error 404 on a URL that i provided and i checked it out in Fiddler and it works fine. my goal is to be able to send my JSON object to my server but i keep getting error 404 for some reason.

This is the Service with the URLs that dont work :

    import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Coupon } from '../Entities/coupon';
import { Observable } from 'rxjs';

@Injectable({
  providedIn: 'root'
})
export class CompanyService {

  private CrtCouponURL = 'http://localhost:8080/CouponSystemWeb/rest/company/CrtCoupon'
  private RmvCouponURL ='http://localhost:8080/CouponSystemWeb/rest/company/RmvCoupon'
  private UpdtCouponURL ='http://localhost:8080/CouponSystemWeb/rest/company/UpdtCoupon'
  private GetAllCouponURL ='http://localhost:8080/CouponSystemWeb/rest/company/GetAllCoupons'
  private couponByTypeURL ='http://localhost:8080/CouponSystemWeb/rest/company/TypeCouponsGet'
  constructor(private http:HttpClient){ }

public createCoupon(coupon:Coupon):Observable<Coupon>{
  return this.http.post<Coupon>(this.CrtCouponURL, coupon ,{withCredentials:true})
}
public deleteCoupon(id:number):Observable<Coupon>{
  return this.http.delete<Coupon>(this.RmvCouponURL+'/?id='+id,{withCredentials:true})
}
public updateCoupon(coupon:Coupon):Observable<Coupon>{
  return this.http.put<Coupon>(this.UpdtCouponURL,coupon,{withCredentials:true})
}
public getAllCoupons():Observable<Coupon[]>{
  return this.http.get<Coupon[]>(this.GetAllCouponURL,{withCredentials:true})
}
public getAllCouponsByType(type:string):Observable<Coupon[]>{
  return this.http.get<Coupon[]>(this.couponByTypeURL+'/?type='+type,{withCredentials:true})
}
}

This is a service with URLs that do work:

@Injectable({
  providedIn: 'root'
})
export class AdminService {
  private companyUrl = 'http://localhost:8080/CouponSystemWeb/rest/admin/company'
  private customerUrl = 'http://localhost:8080/CouponSystemWeb/rest/admin/customer'
  private companyCrtUrl = 'http://localhost:8080/CouponSystemWeb/rest/admin/companyCrt'
  private updateCompURL = 'http://localhost:8080/CouponSystemWeb/rest/admin/UpdateComp'
  private customerCrtUrl = 'http://localhost:8080/CouponSystemWeb/rest/admin/CreateCustomer'
  private customerDelUrl = 'http://localhost:8080/CouponSystemWeb/rest/admin/RmvCustomer'
  constructor(private http: HttpClient) { }

  public createCompany(company: Company): Observable<Company> {
    return this.http.post<Company>(this.companyCrtUrl, company, { withCredentials: true })
  }
  public deleteCompany(id: number): Observable<Company> {
    return this.http.delete<Company>("http://localhost:8080/CouponSystemWeb/rest/admin/mycompany/" + id, { withCredentials: true })
  }
  public updateCompany(id: number, company: Company): Observable<Company> {
    company.id = id;
    return this.http.put<Company>(this.updateCompURL, company, { withCredentials: true })
  }
  public getCompany(id: number): Observable<Company> {
    return this.http.get<Company>(this.companyUrl + "?=id" + id, { withCredentials: true })
  }
  public getAllCompanies(): Observable<Company[]> {
    return this.http.get<Company[]>(this.companyUrl, { withCredentials: true })
  }
  public createCustomer(customer: Customer): Observable<Customer> {
    return this.http.post<Customer>(this.customerCrtUrl, customer, { withCredentials: true })
  }
  public deleteCustomer(id: number): Observable<Customer> {
    return this.http.delete<Customer>(this.customerDelUrl + '?id=' + id, { withCredentials: true })
  }
  public updateCustomer(id: number,customer: Customer): Observable<Customer> {
    return this.http.put<Customer>('http://localhost:8080/CouponSystemWeb/rest/admin/UpdtCustomer', customer, { withCredentials: true })
  }
  public getAllCustomer(): Observable<Customer[]> {
    return this.http.get<Customer[]>(this.customerUrl, { withCredentials: true })
  }
}

few points : I am not using SQL for my database. I dont use : InMemoryDataService.




Aucun commentaire:

Enregistrer un commentaire