Я хочу отправить несколько заархивированных файлов в GITHub из моего локального весеннего приложения.
repos/{:user}/{:repo}/git/refs/heads/{:branchname}
{
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("XXXXXX", 8080));
requestFactory.setProxy(proxy);
RestTemplate restTemplate = new RestTemplate(requestFactory);
String url = new String("https://api.github.com/repos/XXX/MyApplication/git/refs/heads/XXX");
Map<String, String> req = new HashMap<String,String>();
req.put("sha", "9a7fd370e28ea7a4bc8242e7f234s5ed07042cb88");
String jsonObject = JSONParser.quote(payload);
HttpEntity<Object> httpEntity = new HttpEntity<>(headers1);
restTemplate.exchange(url, HttpMethod.POST,httpEntity,Object.class);
}
Error: Exception in thread "main" org.springframework.web.client.HttpClientErrorException: 404 Not Found
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:63)
at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:700)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:653)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:613)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:531)
Используя приведенный ниже POST API, я получаю сообщение «404 not found error».
Method : POST
URL : https://api.github.com/repos/{:user}/{:repo}/git/refs/heads/{:branchname}
{
"sha": "{:new-commit-sha}"
}
Можете ли вы предоставить образец реализации Spring RestTemplate для вышеуказанного api?
Я обнаружил проблему в приведенном выше сценарии. для этого выше идентификатор пользователя и пароль клиента POST в заголовках, и это неверно.
нам нужно предоставить userId и Password в классе BasicAutherizationInceptors, как показано ниже.
resttemplate.getInterceptors().add(new BasicAutherizationInterceptor(userId,Pwd));