我应该以表单的形式将 http 帖子发送到 Web 服务
POST[messageTitle,messageContent,messageFrom]
就像名称为 post 的数组
我四处搜寻,有人说我应该这样做:
nameValuePairs.add(new BasicNameValuePair("POST[]", messageTitle.getText().toString())); nameValuePairs.add(new BasicNameValuePair("POST[]", messageContent.getId())); nameValuePairs.add(new BasicNameValuePair("POST[]", messageFrom.getText().toString())); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
try {
HttpResponse response = httpclient.execute(httppost);
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (statusCode == 200) {
HttpEntity entity = response.getEntity();
InputStream content = entity.getContent();
BufferedReader reader = new BufferedReader(
new InputStreamReader(content));
String line;
while ((line = reader.readLine()) != null) {
stringBuilder.append(line);
}
} else {
Log.e("JSON", "Failed to download file");
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} catch (IOException e) {
// TODO Auto-generated catch block
}
Log.d("Cat", stringBuilder.toString());
}
但它返回 {"result":0} 并且应该返回 {"result":"row"}