1

我有一个使用 Spring boot 用 Ja​​va 开发的 Rest API。它提供了一个与@RequestPart 映射的资源,我收到一个文件和另一个内容以传递给服务。到现在为止,还好。我可以在 Postman 中测试没有问题。

@RestController
@RequestMapping("/content")
public class ContentResource {

private ContentService conteudoService;

@Autowired
public ContentResource(ContentService contentService) {
    this.contentService= contentService;
}

@PostMapping
public ResponseEntity<Content> publicaContent(@RequestPart("file") MultipartFile file, @RequestPart String content ) throws JsonParseException, JsonMappingException, IOException {
    Content convertedContent = new ObjectMapper().readValue(content , Content.class);
    Content storagedContent = contentService.uploadContent(convertedContent, file);
    return ResponseEntity.ok(storagedContent );
}

因此,我需要使用 JWT 的 AuthHttp 从我的 Angular 4 应用程序发出请求。我怎么能做到?

以下是我使用 JWT 实现的其他服务的示例。

@Injectable()
export class StudentService {

url = 'localhost:8080/api/student';

constructor(
   private http: AuthHttp
) { }

save(student: Student): Promise<any> {
return this.http.post(this.url, student)
  .toPromise()
  .then(response => response.json());
}
}
4

0 回答 0