0
我試圖通過POST請求將數據從Android智能手機發送到REST Web服務。POST請求未到達服務器
有對客戶端沒有錯誤,但在服務器端是沒有如果我發送的數據執行的代碼:
客戶:
public void connect2server(View v) throws IOException {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://192.168.1.108:8182");
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("id", "12345"));
nameValuePairs.add(new BasicNameValuePair("stringdata", "data"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
}
服務器端:
public class data_server extends ServerResource {
public static void main(String[] args) throws Exception {
// Create the HTTP server and listen on port 8182
new Server(Protocol.HTTP, 8182, data_server.class).start();
}
@Post
public String toString1() throws IOException {
System.out.println(getRequestEntity().getText());
return "ok";
}
}
這是如何造成的,我該如何解決這個問題?
謝謝,ive添加了log命令,但logcat中沒有顯示錯誤... – FavoriteT
你不需要設置你的url爲'http://192.168.1.108:8182/toString' – Merlin