如何解决如何在android中通过HTTP POST发送二维字符串数组
我有一个二维数组-String[][] fares;
和 1 个一维数组字符串 [] 停止;
我想通过 HTTP POST 连接发送它们。下面是我的代码。如何发送?
我有一个二维数组-String[][] fares;
和 1 个一维数组字符串 [] 停止;
我想通过 HTTP POST 连接发送它们。下面是我的代码。如何发送?
我有一个二维数组-String[][] fares;
和 1 个一维数组字符串 [] 停止;
我想通过 HTTP POST 连接发送它们。下面是我的代码。如何发送?
代码:
主要:
HTTPConnection1 conn = new HTTPConnection1();
conn.execute(stackServer);
功能:
class HTTPConnection1 extends AsyncTask<String,Void,String> {
String result;
String url;
@Override
protected String doInBackground(String... params) {
url = params[0];
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("id","12345"));
nameValuePairs.add(new BasicNameValuePair("message","msg"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse httpResponse = httpclient.execute(httppost);
InputStream inputStream = httpResponse.getEntity().getContent();
//HTTPResult.setText("result3");
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
//HTTPResult.setText("result4");
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
//HTTPResult.setText("result5");
StringBuilder stringBuilder = new StringBuilder();
//HTTPResult.setText("result6");
String bufferedStrChunk = null;
while((bufferedStrChunk = bufferedReader.readLine()) != null){
stringBuilder.append(bufferedStrChunk);
}
result = stringBuilder.toString();
//result= "Sandeep";
} catch (ClientProtocolException e) {
result = "ClientProtocolException";
// TODO Auto-generated catch block
} catch (IOException e) {
result = "IOException";
// TODO Auto-generated catch block
}
return null;
}
@Override
protected void onPostExecute(String bitmap) {
super.onPostExecute(bitmap);
HTTPResult.setText(result);
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。