我想将 http.post(Angular 6)请求发送到我的 Grails 2.4.2 后端。我在 stackoverflow 中搜索了许多解决方案,但没有任何效果。所以我一一为你解答。
现在的情况:
我正在将我的 .zip 检索到一个 dropzone(ngx-dropzone 在 npm 中可用)。我想从我的 angular 前端发送一个 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()
}
}
Run Code Online (Sandbox Code Playgroud)
我有我的 Angular 帖子请求:
onFilesDropped(myzipConfig: File) {
let formData = new FormData();
formData.append('file[]',myzipConfig[0]);
this.http
.post(this.backendPOST, formData).subscribe(results=>{
console.log(results)
})
Run Code Online (Sandbox Code Playgroud)
}
我有一个错误,上面写着:415 不支持的媒体类型。
有人有想法吗?
小智 9
//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)
})
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
14208 次 |
最近记录: |