gpt4 book ai didi

android - 在 JSP 中从 Android 读取 Http post 参数

转载 作者:行者123 更新时间:2023-11-30 02:44:34 26 4
gpt4 key购买 nike

我正在制作一个应用程序,它应该向我的 jsp 发出发布请求。我做了示例中写的所有内容,但它仍然无法正常工作。我在服务器上捕获了请求,但所有参数都返回 null

安卓代码

HttpClient httpClient = new DefaultHttpClient();
HttpResponse response;
String responseString = null;
HttpPost httpPost = new HttpPost(uri);

try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("group", group));
nameValuePairs.add(new BasicNameValuePair("increment", String.valueOf(additionalPoints)));
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

response = httpClient.execute(httpPost);
} catch (ClientProtocolException e) {
} catch (IOException e) {
}

JSP代码

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<%
String group = request.getParameter("group");
String incrementStr = request.getParameter("increment");
%>

我做错了什么?

最佳答案

这样试试

安卓代码

@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
try
{
setContentView(R.layout.main);
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(url);

List<NameValuePair> pairs = new ArrayList<NameValuePair>();
paris.add(new BasicNameValuePair("group", group));
paris.add(new BasicNameValuePair("increment", String.valueOf(additionalPoints)));
post.setEntity(new UrlEncodedFormEntity(pairs));
HttpResponse response = client.execute(post);
}
catch(Exception e)
{
e.printStackTrace();
}
}

JSP代码

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import="java.io.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<%
String group=request.getParameter("group");
String increment=request.getParameter("increment");
%>

</html>

关于android - 在 JSP 中从 Android 读取 Http post 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25296448/

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