我有我试图在Android应用程序来模拟JavaScript代码:Android的POST请求
下面是javascript代码:
text = '{"username":"Hello","password":"World"}';
x.open("POST", url);
x.setRequestHeader("Content-type", "application/json");
x.setRequestHeader("Content-length", text.length);
x.send(text);
这里是我到目前为止的Android应用程序(不工作):
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
httppost.setHeader("Content-type", "application/json");
String text = "\"{\"username\":\"Hello\",\"password\":\"World\"}\"";
httppost.setHeader("Content-length",Integer.toString(text.length()));
httppost.setEntity(new StringEntity(text));
HttpResponse response = httpclient.execute(httppost);
当我试图在eclipse上调试此代码emulater一直运行,而调试器挂起。谢谢!
注:其挂在httpclient.execute(httppost)
你能说出它挂在哪条线上吗? –
@KurtisNusbaum第二个片段的最后一行 –
您是否验证了仿真器与互联网的连接? –