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