我想建立一個HTTP服務器,這將成爲android的聊天應用的請求。因爲我真的很困惑...在我的代碼中,我必須使用套接字?我如何讓客戶端與服務器進行通信?爲了接受來自客戶端的請求並對它們做出響應,我必須在服務器中添加哪些代碼?我在客戶端使用的代碼如下:服務器在Java中(HTTP /插座)
DefaultHttpClient client = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://localhost:80");
List<BasicNameValuePair> nvps = new ArrayList<BasicNameValuePair>();
nvps.add(new BasicNameValuePair("username", username1));
nvps.add(new BasicNameValuePair("password", password1));
try {
UrlEncodedFormEntity p_entity = new UrlEncodedFormEntity(nvps, HTTP.UTF_8);
httppost.setEntity(p_entity);
//Execute HTTP Post Request
HttpResponse response = client.execute(httppost);
Log.v(TAG,"something");
Log.v(TAG, response.getStatusLine().toString());
HttpEntity responseEntity = response.getEntity();
請真的需要一個答案。謝謝!!!
謝謝您的回答。現在對我來說似乎更清楚了。謝謝! – anna