Sha*_*hah 5 android http-post hyperlink
我正在制作一个带有URL的应用程序.*.asp扩展名,我们传递所需的参数,并使用POST方法获得一些字符串结果.
有关如何实现这一目标的任何建议?
更新:
实际上我有一个.net链接,它接受一些POST参数并给我一个结果.我怎么能在Android中做到这一点?
HTTPResponse 应该可以解决问题:
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.yoururl.com");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1); <!-- number should be the amount of parameters
nameValuePairs.add(new BasicNameValuePair("nameOfParameter", "parameter"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity ht = response.getEntity();
BufferedHttpEntity buf = new BufferedHttpEntity(ht);
InputStream is = buf.getContent();
Run Code Online (Sandbox Code Playgroud)
现在您有了一个可以使用的流,可以将数据写入字符串:
BufferedReader r = new BufferedReader(new InputStreamReader(is));
total = new StringBuilder();
String line;
while ((line = r.readLine()) != null) {
total.append(line);
}
Run Code Online (Sandbox Code Playgroud)
祝你好运!
| 归档时间: |
|
| 查看次数: |
4580 次 |
| 最近记录: |