android post 请求,在Android中使用Http Post发送表单数据发布请求

我想使用“ form-data”发送HTTP Post请求.这是其余客户端的屏幕截图,显示我想要什么:

与标题相关的更多信息:

POST /action HTTP/1.1

Host: requsrt-utl

Cache-Control: no-cache

----WebKitFormBoundaryE19zNvXGzXaLvS5C

Content-Disposition: form-data; name="email"

abc@gmail.com

----WebKitFormBoundaryE19zNvXGzXaLvS5C

Content-Disposition: form-data; name="password"

123456

----WebKitFormBoundaryE19zNvXGzXaLvS5C

我尝试使用UrlEncodedFormEntity,但将内容类型设置为“ application / x-www-form-urlencoded”,这是不正确的.

我的Android代码:

HttpClient httpclient = new DefaultHttpClient();

HttpPost httppost = new HttpPost(urlStr);

try {

UrlEncodedFormEntity encodedFormEntity = new UrlEncodedFormEntity(nameValuePairs);

httppost.setEntity(encodedFormEntity);

HttpResponse httpresponse = httpclient.execute(httppost);

return httpresponse.getEntity().getContent();

} catch (ClientProtocolException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

当我使用此功能时,Web服务未获取任何参数,因此它发送一条消息,指出“参数不存在”.

请帮忙!

解决方法:

这可能对您有帮助

HttpPost httppost = new HttpPost(urlStr);

List nameValuePairs = new ArrayList(2);

nameValuePairs.add(new BasicNameValuePair("userid", "12312"));

nameValuePairs.add(new BasicNameValuePair("sessionid", "234"));

httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

标签:http-post,android

来源: https://codeday.me/bug/20191030/1967162.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值