Skip to Content
avatar image
Former Member

HTTPURLConnection 502 /301 response error with java.io.IOException

Hi... I deployed a code in HANA accessing a URL thru HTTPURLConnection

here is my code

URL obj = new URL(url); HttpURLConnection con = (HttpURLConnection) obj.openConnection(); //add reuqest header con.setRequestMethod("POST"); con.setRequestProperty("User-Agent", "Mozilla/5.0 ( compatible ) "); con.setRequestProperty("Accept-Language", "en-US,en;q=0.5"); con.setDoInput(true); con.setRequestProperty("Accept","*/*"); con.setRequestProperty("content-type","application/x-www-form-urlencoded"); con.setRequestProperty("Content-length", "100"); con.setDoOutput(true); con.setUseCaches(false); con.setReadTimeout(15*1000); con.setInstanceFollowRedirects(true); con.setFollowRedirects(true); String urlParameters = "sn=C02G8416DRJM&cn=&locale=&caller=#=12345"; // Send post request con.setDoOutput(true); DataOutputStream wr = new DataOutputStream(con.getOutputStream()); wr.writeBytes(urlParameters); wr.flush(); wr.close(); int responseCode = con.getResponseCode(); System.out.println("\nSending 'POST' request to URL : " + url); System.out.println("Post parameters : " + urlParameters); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); String inputLine; StringBuffer response = new StringBuffer(); System.out.println("Response Code : " + responseCode);

error:

java.io.IOException: Server returned HTTP response code: 502 for URL: (URL link)

can someone please tel me where am i missing? Thanks

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

0 Answers