1
我很抱歉,如果這是重複或重複,需要通過建議或httppost
與HttpURLConnection
或setReadTimeout
setConnectTimeout
通話網址,持續15秒,但問題是我使用的Java 1.4,setReadTimeout()
而setConnectTimeout()
不適用於在java.net的Java 1.4包,任何其他替代方式,下面是我的代碼HttpURLConnection類或HttpPost與setTimeout的針對Java 1.4
URL url;
HttpURLConnection connection = null;
url = new URL(apiURL);
connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "text/json");
connection.setRequestProperty("Content-Length", ""+Integer.
connection.setRequestProperty("Content-Language", "en-US");
我的其他代碼
HttpClient httpClient = new DefaultHttpClient();
HttpPost postRequest = new HttpPost(apiURL);
StringEntity input = new StringEntity(jsonBvmMEssage);
input.setContentType("text/json");
postRequest.setEntity(input);
HttpResponse response = httpClient.execute(postRequest);
感謝提前
出於好奇,什麼是強迫你使用Java 1.4?這真的,真的很老! – 2014-09-22 06:22:17
因爲客戶端還在使用1.4,將來他們只想升級hava,但新的請求需要實現需要設置超時時間的HttpURLConnection/HttpPost,可以幫我在這個上 – David 2014-09-22 07:01:52