首先,我试图能够发送带有以下参数的 HttpResponse:
代码看起来像这样:
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("http://www.syslang.com/frengly/controller");
List<NameValuePair> pairs = new ArrayList<NameValuePair>();
pairs.add(new BasicNameValuePair("src", "en"));
pairs.add(new BasicNameValuePair("dest", "iw"));
pairs.add(new BasicNameValuePair("text", "good"));
pairs.add(new BasicNameValuePair("email", "YYY"));
pairs.add(new BasicNameValuePair("password", "XXX"));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(pairs,HTTP.UTF_8);
httpPost.setEntity(entity);
HttpResponse response = httpClient.execute(httpPost);
HttpEntity httpEntity = response.getEntity();
API 结构可在 http://www.fengly.com/(在 API 选项卡下)获得,共有 5 个参数(src、dest、text、email、password)。
到目前为止,我每次尝试打电话
HttpResponse 响应 = httpClient.execute(httpPost); 我不断收到 IO 异常 :(
之后我应该得到这样的结构:
-<root>
<text>good</text>
<translation>טוב</translation>
<translationFramed>טוב|</translationFramed>
<missing/>
<existing>good,</existing>
<stat>1/1</stat>
</root>
我想我会处理这部分来构建 XML 并根据需要解析它
ps:我查了 Android,通过HTTP POST方法和许多其他链接发送和接收XML ,这对我没有多大帮助。
让我知道是否需要我的应用程序中的任何代码行...
提前致谢。