小编Sha*_*ngh的帖子

httpurlconnection非法状态异常:已连接

我试图发布参数并从输入流读取重定向的页面,但我不知道任何此异常

Exception in thread "main" java.lang.IllegalStateException: Already connected
    at java.net.URLConnection.setDoOutput(URLConnection.java:900)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.setDoOutput(HttpsURLConnectionImpl.java:455)
    at com.company.Main.main(Main.java:58)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Run Code Online (Sandbox Code Playgroud)

码:

try {

        CookieHandler cookieHandler = null;
        CookieManager.setDefault(cookieHandler);


        HttpURLConnection urlConnection = (HttpURLConnection) new URL("site").openConnection();
        InputStream i = new BufferedInputStream(urlConnection.getInputStream());
        StringBuilder stringBuilder =new StringBuilder();


        int c;
        while ((c=i.read())!=-1){
            stringBuilder.append((char)c);
        }

         // for getting the post paramters that is user name and password field
        Pattern p = Pattern.compile("<input name=\"\\w{22}\" type=\"text\" id=\"\\w{22}\" />");
        Matcher matcher = p.matcher(stringBuilder.toString());

        String …
Run Code Online (Sandbox Code Playgroud)

java httpurlconnection

1
推荐指数
1
解决办法
3078
查看次数

标签 统计

httpurlconnection ×1

java ×1