This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Sockets and Internet Protocols and the fly likes HTTP error code 505 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "HTTP error code 505" Watch "HTTP error code 505" New topic

HTTP error code 505

laxmikant upadhyay

Joined: Aug 24, 2012
Posts: 14
i have following code to send http request and receive the respective response. i am using API to send the request but server returns error code 505. when i send same request throgh IE browser it works fine (HTTP error code 200). please help me with this

public class TestClient {

* @param args
public static int connectSiteBook(String urlStr) throws Exception {

URL url = new URL(urlStr);
System.out.println("connectSiteBook()" +"QYERY:"+url.getQuery());
HttpURLConnection c = (HttpURLConnection) url.openConnection();

int resCode = 0;
if (url.getProtocol().equals("https")) {
X509TrustManager trustMgr = new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] arg0,
String arg1) throws CertificateException {

public void checkServerTrusted(X509Certificate[] arg0,
String arg1) throws CertificateException {

public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];

HostnameVerifier hostVerifier = new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return true;

SSLContext context = SSLContext.getInstance("TLS");
System.out.println("connectSiteBook()"+"initialize SSLContext:");
context.init(null, new TrustManager[] { trustMgr }, null);
SSLSocketFactory sockFactory = context.getSocketFactory();
HttpsURLConnection con = (HttpsURLConnection) c;

resCode = c.getResponseCode();
String resMessage = c.getResponseMessage();
String header;
for (int j = 1;; j++) {
header = c.getHeaderField(j);
if (header == null)
System.out.println(c.getHeaderFieldKey(j) + " " + header);

return resCode;

public static void main(String[] args) {
// TODO Auto-generated method stub
String url = "* * * * * ?";

try {
} catch (Exception e) {
// TODO Auto-generated catch block

laxmikant upadhyay

Joined: Aug 24, 2012
Posts: 14
hi all,
the issue has been resolved. the white spaces in the url string was the reason. i just replaced them by '+'.

subject: HTTP error code 505
Similar Threads
How to attach a certificate to a socket and send a https POST request?
SSL - client side - trusting untrusted certificates?
HttpsURLConnection Connects Time out on Geronimo
HttpsUrlConnection - Facing problem while reading the input stream and establishing the cookie
Defining SSL 443 access using provided cacert.pem