Tag Archives: url

Java URL encoding of query string parameters

Questions: Say I have a URL http://example.com/query?q= and I have a query entered by the user such as: random word £500 bank $ I want the result to be a properly encoded URL: http://example.com/query?q=random%20word%20%A3500%20bank%20%24 What’s the best way to achieve this? I tried URLEncoder and creating URI/URL objects but none of them come out quite… Read More »

how to get odata.nextlink from the returned json object in java and call the odata.nextlink url

Questions: Currently I’m using HttpSession session = (HttpSession) request.getSession(); AuthenticationResult result = (AuthenticationResult) session.getAttribute(AuthHelper.PRINCIPAL_SESSION_NAME); String accessToken = result.getAccessToken(); String tenant = session.getServletContext().getInitParameter(“tenant”); url = new URL(“https://graph.windows.net/” + tenant + “/users/” + result.getUserInfo().getUniqueId() + “/memberOf?api-version=1.6”); HttpURLConnection con = (HttpURLConnection) url.openConnection(); // Set the appropriate header fields in the request header. con.setRequestMethod(“GET”); con.setRequestProperty(“api-version”, “1.6”); con.setRequestProperty(“Authorization”, “Bearer “… Read More »

How to get response body using HttpURLConnection, when code other than 2xx is returned?

Questions: I have problem with retrieving Json response in case when server returns error. See details below. How I perform the request I use java.net.HttpURLConnection. I setup request properties, then I do: conn = (HttpURLConnection) url.openConnection(); After that, when request is successful, I get response Json: br = new BufferedReader(new InputStreamReader((conn.getInputStream()))); sb = new StringBuilder();… Read More »

Base URL connecting to database

Questions: I am having a problem with android application connecting to my database. Is the code I wrote correct? public static String BASE_URL = “http://localhost/jobportal/api”; Code: public interface Consts { public static String JOB_PORTAL = “JobPortal”; public static String BASE_URL = “http://localhost:8080/jobportal/api”; public static String IS_REGISTER_SEEKER = “is_register_seeker”; public static String IS_REGISTER_RECRUITER = “is_register_recruiter”; /*API… Read More »

JSON Request adjusting URL params

Questions: I am trying to request data from a URL dependant on the lat/lng searched for. this is my method so far but I am having problems with building the URL with the search params; double latitude = extras.getDouble(“latitude”); double longitude = extras.getDouble(“longitude”); This is lat lng from prev activity This is my maps activity… Read More »