| Author |
HTTP error code 505
|
laxmikant upadhyay
Greenhorn
Joined: Aug 24, 2012
Posts: 14
|
|
hi,
i have following code to send http request and receive the respective response. i am using java.net 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;
con.setSSLSocketFactory(sockFactory);
con.setHostnameVerifier(hostVerifier);
}
resCode = c.getResponseCode();
String resMessage = c.getResponseMessage();
String header;
for (int j = 1;; j++) {
header = c.getHeaderField(j);
if (header == null)
break;
System.out.println(c.getHeaderFieldKey(j) + " " + header);
}
System.out.println("connectSiteBook()"+"getResponseCode:"+resCode);
c.disconnect();
return resCode;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
String url = "https://10.45.76.100:55500/sitebook/viewParameter.htm?action=saveOne&cli=cli&listOfVals=Application____CronTriggerExpression____* * * * * ?";
try {
System.out.println(connectSiteBook(url));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
|
 |
laxmikant upadhyay
Greenhorn
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 '+'.
cheers
|
 |
 |
|
|
subject: HTTP error code 505
|
|
|