Skip to Content
0

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

Jun 20, 2017 at 05:45 PM

129

avatar image
Former Member

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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

0 Answers