github api发布404,但没问题

mgdq6dx1  于 2021-07-12  发布在  Java
关注(0)|答案(0)|浏览(241)

我对一个简单的任务很生气。我制作了一个虚拟的github帐户和存储库来做这个实验,这样我就可以共享安全令牌了,这样你就可以在你的终端上试试看到底发生了什么-我知道我被正确地诱惑了-令牌拥有所有权限
下面的代码给了我一个404

String requestBody = """
  {
  "owner" : "example42gdrive",
  "repo" : "Example1",
  "message" : "nextCommit",
  "content" : "newfilecontent",
  "sha" : "3db88097240677d34f3b2a4892f8d00f9c63d6dc"
  }
  """;
var url1="https://api.github.com/repos/example42gdrive/Example1/";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
  .uri(URI.create(url1+"contents/bar/foo.txt"))
  .header("Authorization","token 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")
  .header("Accept", "application/vnd.github.v3+json")
  .POST(HttpRequest.BodyPublishers.ofString(requestBody))
  .build();    
HttpResponse<String> response = client.send(
  request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body().replace(",","\n"));
System.out.println(response.statusCode());//getting 404

但是,如果我对post行进行注解,请求将变成get,并且我将获得有关读取文件/bar/foo.txt的正确信息
我做错了什么?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题