为了账号安全,请及时绑定邮箱和手机立即绑定

post请求的参数如何添加?

post请求的参数如何添加?老师的视频中只是一个字符串,能否帮忙指出如何添加post方法携带的参数?谢谢老师

正在回答

3 回答

嗯第二版就是带着你通过OOP来搭建自己的框架,敬请期待,框架的名都有了叫king'sPHP

pflouqlxican

0 回复 有任何疑惑可以回复我~

以我的经验,只要不是就显示一行notfound,其他的什么都可以

spd10000binqtdnjhspjyasx

0 回复 有任何疑惑可以回复我~

public static String httpPost(String url,List<BasicNameValuePair> list) {

String result = null;

RequestConfig requestConfig = RequestConfig.custom()

.setConnectTimeout(5000)   //设置连接超时时间

.setConnectionRequestTimeout(5000) // 设置请求超时时间

.setSocketTimeout(5000)

.setRedirectsEnabled(true)//默认允许自动重定向

.build();

CloseableHttpClient closeableHttpClient = HttpClients.createDefault();

HttpPost httpPost = new HttpPost(url);

httpPost.setConfig(requestConfig);

try {

UrlEncodedFormEntity entity = new UrlEncodedFormEntity(list, "UTF-8");

//设置post请求参数

httpPost.setEntity(entity);

HttpResponse httpResponse = closeableHttpClient.execute(httpPost);

if(httpResponse.getStatusLine().getStatusCode() == 200) {

result = EntityUtils.toString(httpResponse.getEntity());

}

} catch (Exception e) {

e.printStackTrace();

}finally {

try {

closeableHttpClient.close();

} catch (IOException e) {

e.printStackTrace();

}

}

return result;

}


0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

post请求的参数如何添加?

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信