我想向我的Grails 2.4.2后端发送一个http.post(角度6)请求。我在stackoverflow中搜索了许多解决方案,但没有任何效果。所以我要回答大家。
现在的情况:
我正在将我的.zip检索到一个dropzone(在npm中可用ngx-dropzone)。我想将一个zip从我的前端发送到我的grails后端。我有一个Grails资源正在检索我的数据。
@Path('/api/newmodele')
class NewModeleResource {
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
Response newmodele(){
CommonsMultipartFile downloadedFile = request.getFile('document')
return Response.ok("toto" as JSON).build()
}
}
我有我的Angular职位要求:
onFilesDropped(myzipConfig: File) {
let formData = new FormData();
formData.append('file[]',myzipConfig[0]);
this.http
.post(this.backendPOST, formData).subscribe(results=>{
console.log(results)
})
}
而且我看到一个错误:415不支持的媒体类型。
有人有主意吗?
//pass httpOptions to the function
const httpOptions = {
headers: new HttpHeaders({'Content-Type': 'application/json'})
}
this.http
.post(this.backendPOST, formData, httpOptions).subscribe(results=>{
console.log(results)
})
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句