Reputation: 99
I am calling a url using this code
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);
i am running a webservice in development server using local source code.the reponse is not coming back
note:-the service running time is 7-8 min.
Upvotes: 0
Views: 183
Reputation: 1910
Try this.
Imports are given below :
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import java.io.InputStream;
import java.io.InputStreamReader;
Code is given below :
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);
Upvotes: 1