java.io.IOException: Server returned HTTP response code: 500 for URL: http://physics.whu.edu.cn/show.asp?id=278 java
java.io.IOException: Server returned HTTP response code: 403 for URL spring
可是本身卻能夠用瀏覽器訪問,發現多是服務器對咱們這種java程序屏蔽了。 apache
由於服務器的安全設置不接受Java程序做爲客戶端訪問,解決方案是設置客戶端的User Agent 數組
url = new URL("http://physics.whu.edu.cn/show.asp?id=278");
HttpURLConnection connection = (HttpURLConnection) url.
openConnection();
connection.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)"); 瀏覽器
這樣就能夠訪問了。 安全
Exception in thread "main" com.caucho.hessian.client.HessianConnectionException: 500: java.io.IOException: Server returned HTTP response code: 500 for URL: http://xx:8088/hessian/testServlet
這是你引用的jar包引發的,若是你使用上面的例子,而使用hessian-3.1.5.jar或更高版本的包就會出現上述錯誤。更換hessian-3.0.20.jar如下的包就能夠了。
至於具體的緣由我也沒有調查過。 服務器
運行客戶端程序,拋出異常: dom
Exception in thread "main" com.caucho.hessian.client.HessianConnectionException: 500: java.io.IOException: Server returned HTTP response code: 500 for URL: http://127.0.0.1:8080/htest/hello
at com.caucho.hessian.client.HessianProxy.invoke(HessianProxy.java:202)
at $Proxy0.getPerson(Unknown Source)
at example.BasicClient.main(BasicClient.java:25) 測試
查看服務器日誌,獲得異常信息:
java.lang.IllegalStateException: Serialized class example.Person must implement java.io.Serializable
at com.caucho.hessian.io.SerializerFactory.getDefaultSerializer(SerializerFactory.java:262)
at com.caucho.hessian.io.SerializerFactory.getSerializer(SerializerFactory.java:234)
at com.caucho.hessian.io.Hessian2Output.writeObject(Hessian2Output.java:406)
... ui
異常提示 example.Person 必須實現 java.io.Serializable 接口。
(2)Serializable 和序列化
對於簡單數據類型,如int, double, char,數組等,以及經常使用的一些類型,如String,java.util.Date,List, Map等,Hessian 自己對其進行了特殊處理,也就是 Hessian 對其進行了序列化操做,可是 Hessian 不可能瞭解其餘的類以及在您的應用程序中使用的那些類。對於這些類,Hessian 則要求這些類自己可以被序列化,也就是要求這些必須實現 Serializable 接口。
(3)正確的作法
讓 Person 實現 Serializable 接口,則 Person.java 應該被修改爲:
package example;
import java.io.Serializable;
import java.util.Date;
public class Person implements Serializable{
private int id = 0;
private String name = "";
private Date birthday = null;
...
從新啓動 Web 服務器,就能夠成功運行客戶端程序了。
1,org.springframework.remoting.RemoteAccessException: Cannot access Hessian service at [http://61.152.162.173/remote/remoteService];
出現這個異常通常是由於服務端操做出現異常引發的
2,com.caucho.hessian.io.HessianProtocolException: 501: java.io.IOException: Server returned HTTP response code: 501 for URL: http://61.152.162.173/remote/remoteService
出現這個緣由,多是由於代理問題(個人機器是經過squid代理上網的,並非經過路由器),501服務器沒法提供對請求中所要求功能的支持。若是服務器沒法識別請求方法就會迴應此狀態代碼,這意味着不能迴應請求所要求的任何資源。
3,org.springframework.remoting.RemoteConnectFailureException: Cannot connect to Hessian service at http://127.0.0.1:8080/remote/remoteService]; nested exception is java.net.ConnectException: Connection refused: connect
鏈接不上hessian服務器.
4,客戶端拋出的異常:
Exception in thread "main" java.io.IOException: Server returned HTTP response code: 500 for URL: http://192.168.100.196/remote/FileServlet
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1174)
服務端拋出的異常以下:
[org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/].[FileServlet]] - Servlet.service() for servlet FileServlet threw exception
com.caucho.hessian.io.HessianProtocolException: upload: expected end of call ('z') at '
解決:由於個人服務端要求上傳的文件必須在userfiles目錄下(代碼:filePath.indexOf("userfiles");),判斷我以前測試的文件沒有放到該目錄下,就出現了這種錯誤.
5,爲何客戶端是對象,到了服務端就是map了呢????? 緣由:個人list在上傳前保存的是對象,經測試也不是map型,但到服務端從list獲取的變成了map型,經分析是由於目錄結構的緣由,個人客戶端po放到了domain目錄下,服務端po放到domainobject下,我是用netCourseInfo組裝信息的,客戶端和服務端這兩個文件不一樣(由於import的po的位置不同),因此形成服務端反序列化時出現問題.