我正在使用java中的webService调用它运行良好,但我需要SetTimout进行连接。以下是我的要求。
这是我的连接建立代码,得到回复。
ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
String urlParameters = ow.writeValueAsString(something);
urlParameters = "{ \"something\":" + urlParameters + "}" ;
byte[] postData = urlParameters.getBytes( StandardCharsets.UTF_8 );
int postDataLength = postData.length;
String request = "http://something.com";
url = new URL( request );
postConnection = (HttpURLConnection) url.openConnection();
postConnection.setDoOutput( true );
postConnection.setInstanceFollowRedirects( false );
postConnection.setRequestMethod( "POST" );
postConnection.setRequestProperty( "Content-Type", "application/json");
DataOutputStream wr = new DataOutputStream( postConnection.getOutputStream());
wr.write( postData );
wr.flush();
wr.close();
BufferedReader in = new BufferedReader(
new InputStreamReader(postConnection.getInputStream()));
Thanx寻求帮助