尝试执行POST,PUT和DELETE时出现错误405

时间:2017-11-10 05:14:48

标签: angular http typescript html-table angular-http

我正在尝试使用json blob中的API,然后当我尝试使用POST,PUT和DELETE方法时出现这样的错误:DELETE https://jsonblob.com/fbd3fa51-c4fe-11e7-96cf-e300ee4b68637 405 ()

这是json blob link

	//request
    getStocksAPI(): Observable<any>
    {
        //return this.http.get("http://localhost:3000/Student/") //perhatikan port localhost
        return this.http.get("https://jsonblob.com/api/jsonblob/fbd3fa51-c4fe-11e7-96cf-e300ee4b6863")
        .map( (res: Response) => res.json() )
        .catch((error:any) => Observable.throw(error.json().error || 'Server error'))
    }
    //end of request

	
	//add
    addStudent(newId: string, newName: string, newYear: string, newSemester: string, newMajor: string, newScore: string, newEmail: string): Observable<any>
    {
        //return this.http.post("http://localhost:3000/Student/", {id: newId, name: newName, year: newYear, semester: newSemester, major: newMajor, score: newScore, email: newEmail});
        return this.http.post("https://jsonblob.com/fbd3fa51-c4fe-11e7-96cf-e300ee4b6863", {id: newId, name: newName, year: newYear, semester: newSemester, major: newMajor, score: newScore, email: newEmail});
    }
    //end of add
	
	//update
	updStudent(Id: string, newName: string, newYear: string, newSemester: string, newMajor: string, newScore: string, newEmail: string): Observable<any>
    {
        return this.http.put("https://jsonblob.com/fbd3fa51-c4fe-11e7-96cf-e300ee4b6863"+Id,
            {
                Id: Id,
                name: newName, 
                year: newYear,
                semester: newSemester,
                major: newMajor,
                score: newScore,
                email: newEmail
            });
             
        // return this.http.put("http://localhost:3000/Student/"+Id,
        // {
        //     Id: Id,
        //     name: newName, 
        //     year: newYear,
        //     semester: newSemester,
        //     major: newMajor,
        //     score: newScore,
        //     email: newEmail
        // });
     }
     //end of update
	 
	//delete
    delStudent(id: string): Observable<any>
    {
        //return this.http.delete("http://localhost:3000/Student/" +id);
        return this.http.delete("https://jsonblob.com/fbd3fa51-c4fe-11e7-96cf-e300ee4b6863"+id);
    }
    //end of delete

在尝试json blob的API之前,CRUD操作使用json-server localhost:3000正常工作。使用API​​后只使用GET方法。 POST,PUT和DELETE给我错误405。 任何人都可以帮我解决这个错误吗?

如果需要更多代码段,请与我们联系。谢谢。

0 个答案:

没有答案
相关问题