Http发布如何将参数添加到我的URL

时间:2016-11-17 03:44:13

标签: java android android-asynctask httpurlconnection

我想将我的Fbid添加到php DB,我该怎么做?

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="estilo_segundo.css">
<body>
<button onclick="createDiv()">Click</button>
</body>

我的private class HttpAsyncTask extends AsyncTask<String, Void, String> { @Override protected String doInBackground(String... data) { String result = null; try { // 1. create HttpClient URL url = new URL(data[0]); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setReadTimeout(10000); connection.setConnectTimeout(15000); connection.setRequestMethod("POST"); connection.setDoInput(true); List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("fbid", fbid)); OutputStream os = connection.getOutputStream(); BufferedWriter writer = new BufferedWriter( new OutputStreamWriter(os, "UTF-8")); writer.write(getQuery(params)); writer.flush(); writer.close(); os.close(); connection.connect(); } catch (Exception e) { Log.d("InputStream", e.getLocalizedMessage()); } return result; } private String getQuery(List<NameValuePair> params) throws UnsupportedEncodingException { StringBuilder result = new StringBuilder(); boolean first = true; for (NameValuePair pair : params) { if (first) first = false; else result.append("&"); result.append(URLEncoder.encode(pair.getName(), "UTF-8")); result.append("="); result.append(URLEncoder.encode(pair.getValue(), "UTF-8")); } return result.toString(); } 为24,compileSdkVersion&#34; 24.0.1&#34;。
为什么我不能添加到数据库?这是因为buildToolsVersion已被弃用了吗?

0 个答案:

没有答案