저는 Spring Boot 및 IntelliJ IDEA를 사용하여 REST API를 개발했습니다. 해당 API가 실행 중입니다. Postman &이 액세스 할 수 있으며 관련 JSON 응답을 제공합니다.C# Windows Form에서 REST API에 액세스 할 수 없습니다.
그런 다음 C# windows 폼 응용 프로그램에서 액세스하려고했습니다. 웹 참조로 추가하려고했습니다. 하지만 해당 버튼이 비활성화되었습니다. 내 코드의 문제점은 무엇입니까? 비주얼 스튜디오에 와서 8080/학생/안녕하세요 JSON 응답 : 나는 로컬 호스트로 URL을 제공하는 경우
@RestController
@RequestMapping("/students")
public class StudentController {
@Autowired
private StudentService studentService;
@RequestMapping(value="/hello")
String home() {
return "Hello World!";
}
@RequestMapping(value="getAllStudents",method = RequestMethod.GET)
public Collection<Student> getAllStudents(){
return studentService.getAllStudents();
}
@RequestMapping(value = "/{id}",method = RequestMethod.GET)
public Student getStudentById(@PathVariable("id") int id)
{
return studentService.getStudentById(id);
}
@RequestMapping(value = "/{id}" , method = RequestMethod.DELETE)
public void deleteStudentById(@PathVariable("id") int id)
{
studentService.removeStudentById(id);
}
. 그러나 웹 참조로 추가 될 수는 없습니다.
이에 대한 해결책은 무엇인가
...?
요의 주요 문제 ur C# 코드는 Java 코드 –
.NET에서 REST API를 전혀 사용하지는 않았지만 Visual Studio에서 '웹 참조'는 SOAP 웹 서비스와 함께 사용하도록되어 있다고 항상 생각했습니다. REST API를 사용하려면 'HttpClient'로 직접 빌드하거나 타사 라이브러리를 사용해야한다고 생각합니다. – fharreau