我有我試圖在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第二個片段的最後一行 –
您是否驗證了仿真器與互聯網的連接? –