получение кода состояния 403 при выполнении запроса POST - PullRequest
0 голосов
/ 12 февраля 2020

Я пытаюсь сделать вызов методом POST в groovy. Я нашел много вещей в StackOverflow, но все же я не могу достичь своей цели.

System.setProperty("http.proxyHost", "test")
System.setProperty("http.proxyPort", "8080")
System.setProperty("http.proxyUser", "test")
System.setProperty("http.proxyPassword", "test")
String postResult
    ((HttpURLConnection)new URL('http://reqres.in/api/register').openConnection()).with({
        requestMethod = 'POST'
        doOutput = true
        setRequestProperty('Content-Type', 'application/json') 
        outputStream.withPrintWriter({printWriter ->
            printWriter.write('{\n' +
                    '    "email": "eve.holt@reqres.in",\n' +
                    '    "password": "pistol"\n' +
                    '}') 
        })
        // Can check 'responseCode' here if you like.
        postResult = inputStream.text
    })

Я получаю *Exception in thread "main" java.io.IOException: Server returned HTTP response code: 403 for URL: http://reqres.in/api/register*

...