服务器端如何提取客户端POST的数据

ESC尛蜜蜂 ESC尛蜜蜂 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
客户端POST方法

private String postJsonData(String url,Object obj) {
HttpClient client =null;
try {
BasicHttpParams httpParams = new BasicHttpParams();
ConnManagerParams.setTimeout(httpParams,10000);
HttpConnectionParams.setConnectionTimeout(httpParams, 10000);
HttpConnectionParams.setSoTimeout(httpParams, 20000);
//DefaultHttpClient client = new DefaultHttpClient(httpParams);
client = new DefaultHttpClient(httpParams);

//HttpClient client = new DefaultHttpClient();
//HttpParams httpParams = client.getParams();

//HttpConnectionParams.setConnectionTimeout(httpParams, 10000);
//HttpConnectionParams.setSoTimeout(httpParams, 10000);
HttpResponse response;


HttpPost httpPost = new HttpPost(url);
httpPost.addHeader("Accept", "application/json;charset=utf-8");
httpPost.addHeader("Content-Type", "application/json;charset=utf-8");
Gson gson = new Gson();
httpPost.setEntity(new StringEntity(gson.toJson(obj), "utf-8"));//
response = client.execute(httpPost);


HttpEntity entity = response.getEntity();
if (entity != null) {
String result = EntityUtils.toString(entity);
return result;

}
} catch (ClientProtocolException e) {
e.printStackTrace();
// TODO Auto-generated catch block
return null;

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;

} catch (Exception e) {
e.printStackTrace();
return null;
}finally {
if (client != null && client.getConnectionManager() != null) {
client.getConnectionManager().shutdown();
}
}
return null;

}


调用

String sb = postJsonData(url, ContactUsReq);


ContactUsReq是个java类已经赋值

ContactUsReq contactUsReq = new ContactUsReq();
contactUsReq.setUsername(usrInfo[0]);
contactUsReq.setRandomstring(randomstring);
contactUsReq.setVerifystring(verifystring);
contactUsReq.setContent(contact);


我想知道服务器如何获取我set的值?
...全文

相关推荐

评论 4
收藏 已收藏
分享
返回顶部
ESC尛蜜蜂
Android 80,490 成员 91,375 内容