嗨,这是Android客户端中的HTTP Post Request方法。我不知道如何在Restful Web服务器中实现@POST方法。
public class AndroidHTTPRequestsActivity extends Activity
{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Creating HTTP client
HttpClient httpClient = new DefaultHttpClient();
// Creating HTTP Post
HttpPost httpPost = new HttpPost(
"http://localhost:8080/GPS_Taxi_Tracker_Web_Server/resources/rest.android.taxi.androidclientlocation/Login");
// Building post parameters
// key and value pair
List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(2);
nameValuePair.add(new BasicNameValuePair("email", "user@gmail.com"));
nameValuePair.add(new BasicNameValuePair("message",
"Hi, trying Android HTTP post!"));
// Url Encoding the POST parameters
try {
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePair));
} catch (UnsupportedEncodingException e) {
// writing error to Log
e.printStackTrace();
}
// Making HTTP Request
try {
HttpResponse response = httpClient.execute(httpPost);
// writing response to log
Log.d("Http Response:", response.toString());
} catch (ClientProtocolException e) {
// writing exception to log
e.printStackTrace();
} catch (IOException e) {
// writing exception to log
e.printStackTrace();
}
}
java restful web服务中post方法的实现是什么,这是我的Rest服务器的代码有什么问题?
@POST
@Path("{Login}")
@Consumes({"application/xml"})
public void Add(@PathParam("email") String email,AndroidClientLocation entity) {
entity.setEmail(email);
super.create(entity);
}
答案 0 :(得分:0)
http://developer.android.com/tools/devices/emulator.html#networkaddresses
10.0.2.2 Special alias to your host loopback interface (i.e., 127.0.0.1 on your
development machine)
http://localhost:8080/.
向localhost发送请求'表示将其发送到本地计算机。在你的情况下,这将是Android设备。您希望将请求发送到桌面计算机,这是一个远程主机。问题是Appengine dev_sever默认只绑定到本地地址,因此无法远程访问(即,从您的Android设备)。您需要传递--address选项才能从外部访问。检查计算机的IP并将其作为地址传递。类似的东西:
dev_appserver.cmd --address = 192.168.2.220
答案 1 :(得分:0)
多个问题..
问题的答案可能会更多地澄清请求。