連線Http Server的程式碼
連線Http Server的程式碼很多,最近我看到一份資料中連線HTTP程式碼不錯,
只是對於他使用ByteArrayOutputStream來in.read()沒有理解,哪位能夠指點?
只是對於他使用ByteArrayOutputStream來in.read()沒有理解,哪位能夠指點?
String url = "http://www.developnet.co.uk/SerializeServlet"; HttpConnection conn = (HttpConnection) Connector.open(url); conn.setRequestMethod(HttpConnection.POST); conn.setRequestProperty("Content-Type", "application/octet-stream "); conn.setRequestProperty("User-Agent","Profile/MIDP-1.0 Configuration/CLDC-1.0"); conn.setRequestProperty("Content-Language", "en-US"); conn.setRequestProperty("Accept", "application/octet-stream"); conn.setRequestProperty("Connection", "close"); // optional byte[] data =.....; //傳送請求request conn.setRequestProperty("Content-Length", Integer.toString(data.length)); OutputStream os = conn.openOutputStream(); os.write(data); os.close(); //以下是接受response int rc = conn.getResponseCode(); if (rc == HttpConnection.HTTP_OK) { int len = (int)conn.getLength(); InputStream in = conn.openInputStream(); if (len != -1) { int total = 0; data = new byte[len]; while (total < len) { total += in.read(data, total, len - total); } } else { ByteArrayOutputStream tmp = new ByteArrayOutputStream(); int ch; while ((ch = in.read()) != -1) { tmp.write(ch); } data = tmp.toByteArray(); } //將data處理 ............. } |
相關文章
- http的長連線和短連線HTTP
- Socket連線和Http連線HTTP
- HTTP 持久連線HTTP
- HTTP長連線HTTP
- HTTP連線池HTTP
- SQL Server連線SQL Server、SQL Server連線ORACLE 連結伺服器SQLServerOracle伺服器
- SQL SERVER 自連線、外連線SQLServer
- Http持久連線與HttpClient連線池HTTPclient
- 連線SQL ServerSQLServer
- PostgreSQL server端接收連線後fork程式SQLServer
- http Socket長連線HTTP
- http server原始碼解析HTTPServer原始碼
- HTTP代理的兩種連線方式HTTP
- .NET連線SQL ServerSQLServer
- HTTP非持續連線和持續連線HTTP
- HTTP長連線和短連線原理淺析HTTP
- SQL Server中內連線和外連線的區別SQLServer
- 一文讀透HTTP的長連線和短連線HTTP
- 圖解 HTTP 連線管理圖解HTTP
- HTTP 長連線問題HTTP
- SQL Server linked server 連線OracleSQLServerOracle
- HTTP長連線、短連線究竟是什麼?HTTP
- 連線SQL SERVER的公共類 (轉)SQLServer
- telnet連線socket serverServer
- SQL Deverlop連線SQL ServerSQLdevServer
- Perl 連線 SQL Server (轉)SQLServer
- dedicated server連線測試Server
- 遠端連線SQL ServerSQLServer
- Http和Socket連線區別HTTP
- python 怎麼連線 sql server,不是連線 mysqlPythonServerMySql
- NavicatPremium 連線SQL Server 、MySQL等REMServerMySql
- SQL Server連線不上原因SQLServer
- 最近學習了Http連線池HTTP
- http連線複用進化論HTTP
- GOLANG探測HTTP連線斷開GolangHTTP
- 去掉連結a的虛線框程式碼例項
- HTTP協議中的短輪詢、長輪詢、長連線和短連線HTTP協議
- 如何使用Linked Server連線Oracle與SQL ServerServerOracleSQL