2017-04-04 177 views
0

我使用此代碼服務器未響應返回

URL url = new URL(urlString); 
       HttpURLConnection httpCon = (HttpURLConnection) url 
         .openConnection(); 
       httpCon.setRequestMethod("HEAD"); 
       httpCon.setConnectTimeout(1200000); 
       httpCon.setReadTimeout(1200000); 
       httpCon.setRequestMethod("GET"); 
       httpCon.setRequestProperty("Content-Type", "application/json"); 
       int responseCode = httpCon.getResponseCode(); 
       System.out.println(responseCode); 

我使用本地源code.the效應初探運行在開發服務器web服務調用的URL是不回來

注:-The服務運行時間爲7-8分鐘。

+0

你想用'API Call'得到'Response'在'JSON':下面

import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import java.io.InputStream; import java.io.InputStreamReader; 

代碼給出? – user3441151

+0

yes @ user3441151我有一個API將返回JSON,但數據是如此之大,所以它需要8個薄荷糖來運行我可以看到服務正在服務器日誌中運行,但完成後它不會返回值。 –

+0

你從這個API調用中獲得什麼?它是JSON數組還是JSON對象? – user3441151

回答

1

試試這個。

進口量如下:

URL url = new URL(urlString); 
HttpURLConnection httpCon = (HttpURLConnection) url.openConnection(); 
httpCon.setRequestMethod("HEAD"); 
httpCon.setConnectTimeout(1200000); 
httpCon.setReadTimeout(1200000); 
httpCon.setRequestMethod("GET"); 
httpCon.setRequestProperty("Content-Type", "application/json"); 
int responseCode = httpCon.getResponseCode(); 
System.out.println(responseCode); 

//For getting the response in JSON 
JsonParser jp = new JsonParser(); 
JsonElement root = jp.parse(new InputStreamReader((InputStream) httpCon.getContent())); 
JsonObject innerRootobj = root.getAsJsonObject(); 
System.out.println("innerRootobj : " + innerRootobj); 
相關問題