如果重复或重复,我很抱歉,需要建议httppost
或HttpURLConnection
setReadTimeout
或setConnectTimeout
拨打网址15秒,问题是我正在使用java 1.4,setReadTimeout()
和setConnectTimeout()
不适用于java.net下的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);
提前致谢
答案 0 :(得分:0)
最后,我发现了这个,
HttpPost postRequest = new HttpPost(apiURL);
HttpParams httpParameters = new BasicHttpParams();
int timeoutConnection = 15000;
HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
int timeoutSocket = 15000;
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);
HttpResponse response = httpClient.execute(postRequest);
希望这会有效,将会测试和更新