java.net.ProtocolException:无法重置方法:已连接

时间:2019-11-06 05:49:13

标签: java http httpurlconnection

我正在DEV环境中执行以下代码,没有任何问题。

InputStream inStream = null;
DataOutputStream dOutStream = null;
InputStream ipcInStream = null;
DataOutputStream ipcOutStream = null;
String strUser = "xxxx";
String strPswrd = "xxxxxxx";
String serverURL = "xxxxx.com";
String serverFile = "xxxx";         
String requestData = "xxxx";
// instantiate url using a defined protocol(String), url(String), port(int) and file(String)
URL urlOrder = new URL("HTTPS", serverURL, 443, serverFile);
// proxy related Code           
String proxyHost = "xxxx";
String proxyPort = "xxxx";
Proxy proxy = null;
if (proxyHost != null && proxyPort != null) {
    // Proxy instance
    proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(
                    proxyHost, Integer.parseInt(proxyPort)));
}
// instantiate URLConnection from URL
URLConnection urlConn = (proxy == null) ? urlOrder
                .openConnection() : urlOrder.openConnection(proxy);
// Set Input Output booleans
urlConn.setDoInput(true);
urlConn.setDoOutput(true);

// Set the content type of the request
urlConn.setRequestProperty("Content-Type", "text/xml");

// Set the encoding and transfer file structure
urlConn.setRequestProperty("Accept-Encoding", "gzip, deflate");

// connect to the url referenced by this URLConnection
urlConn.connect();
// Get an output stream
dOutStream = new DataOutputStream(urlConn.getOutputStream());
dOutStream.writeBytes(requestData);
// flush the output stream
dOutStream.flush();

但是当我在质量检查中运行相同的代码时,我在行中遇到了以下异常

dOutStream = new DataOutputStream(urlConn.getOutputStream());

例外是:

java.net.ProtocolException: Can't reset method: already connected

需要有关为何引发此异常的帮助。

0 个答案:

没有答案