JAVA-HTTP请求-响应错误

时间:2018-11-01 12:12:37

标签: java http amazon

我在亚马逊创建了tre API getway模拟,每次GET返回200。 我创建了以下代码:

public static void getRequest(String url) throws IOException {

        URL urltouse = new URL(url);
        HttpURLConnection httpCon = (HttpURLConnection) urltouse.openConnection();
        httpCon.setDoOutput(true);
        httpCon.setRequestMethod("GET");
        OutputStreamWriter out = new OutputStreamWriter(
                httpCon.getOutputStream());
        System.out.println(httpCon.getResponseCode());
        System.out.println(httpCon.getResponseMessage());
    }

针对网址运行它时:https:xxxxxxxx / v1 / LZ_service99 / LZ_tenant99 /未处理,我收到响应代码403。为什么?如果我将URL放在crome中,则得到正确的json模拟。也许我需要使用其他http请求?先前的代码是:

 ResponseEntity<String> response = this.restTemplate.getForEntity(url, String.class, new Object[0]);

而且我不得不避免使用restTemplate,因为它需要使用springDependecy来避免使用它。

0 个答案:

没有答案