【发布时间】:2011-10-16 14:06:32
【问题描述】:
我正在尝试通过 POST 请求将数据从 Android 智能手机发送到 REST Web 服务。
客户端没有错误,但是如果我发送了数据,服务器端没有执行代码:
客户:
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";
}
}
这是如何引起的,我该如何解决?
【问题讨论】:
标签: android http rest post restlet