android - 如何在android中通过HTTP POST发送二维字符串数组
问题描述
我有一个二维数组-String[][] 票价;
和 1 1-D array-String [] 停止;
我想通过 HTTP POST 连接发送它们。下面是我的代码。如何发送它们?
我有一个二维数组-String[][] 票价;
和 1 1-D array-String [] 停止;
我想通过 HTTP POST 连接发送它们。下面是我的代码。如何发送它们?
我有一个二维数组-String[][] 票价;
和 1 1-D array-String [] 停止;
我想通过 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);
}
解决方案
推荐阅读
- asp.net - 通过 WCF 发送客户端证书导致错误:“客户端身份验证方案‘匿名’禁止 HTTP 请求”
- php - 有没有办法在 PHP 中处理图表?
- php - Laravel 序列化数据的总和值
- javascript - 如何有条件地解构对象?
- android - Android Splash Screen doesn't display
- c# - 在 C# 中,我试图显示上一个 WriteLine 方法中的文本字符串。得到编译器错误
- python - 使用请求模块来使用 API?
- java - 监听器未听到 NatTable 单元格点击
- javascript - 如何在 React.js 表中显示 MySQL 表?
- javascript - How to find most common number in array using link in JavaScript?