我想将字符串从客户端传输到 Web 服务器。
客户代码:
String uriString = "http://128.128.4.120:8080/GCMService/GCMBroadcast";
URI uri = null;
try {
uri = new URI(uriString);
} catch (URISyntaxException e) {
e.printStackTrace();
}
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPut httpPut = null;
if(uri!=null)
httpPut = new HttpPut(uri);
HttpParams params = new BasicHttpParams();
params.setParameter("mymsg", "HELLO SERVER");
httpClient.setParams(params);
HttpResponse resp = httpClient.execute(httpPut);
服务器代码:
@Override
protected void doPut(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
System.out.println(req.getParameter("mymsg"));
}
每次客户端请求 httpPut 时,服务器的控制台都会打印“null”,我希望应该是“HELLO SERVER”。这是如何引起的,我该如何解决。