gpt4 book ai didi

android - 使用android将两个参数传递给webservice

转载 作者:行者123 更新时间:2023-11-29 17:40:52 25 4
gpt4 key购买 nike

params[0] 存储在 .net 框架中创建的 web 服务的用户。所以在我的 web 方法中有两个参数“StartIndex”和“EndIndex”,所以现在我如何将参数传递给 android 中的 Web 方法。

    HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost( params[0]);
HttpResponse response = client.execute(post);

最佳答案

您可以使用 NameValuePair 列表将多个参数放入您的 POST 请求,如:

try {
HttpPost httpPost = new HttpPost("url");
List<NameValuePair> parameters = new ArrayList<NameValuePair>(2);
parameters.add(new BasicNameValuePair("login", "trout"));
parameters.add(new BasicNameValuePair("password", "salmon"));
httpPost.setEntity(new UrlEncodedFormEntity(parameters, "UTF-8"));

HttpClient httpClient = new DefaultHttpClient();
HttpResponse httpResponse = httpClient.execute(httpPost);

String response = EntityUtils.toString(httpResponse.getEntity(), "UTF-8");
} catch (UnsupportedEncodingException e) {

} catch (ClientProtocolException e) {

} catch (IOException e) {

}

关于android - 使用android将两个参数传递给webservice,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28826778/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com