美文网首页
HttpPost 两种消息体形式 —— UrlEncodedFo

HttpPost 两种消息体形式 —— UrlEncodedFo

作者: Sandy_678f | 来源:发表于2018-11-12 21:13 被阅读0次

一、UrlEncodedFormEntity

List<NameValuePair> pairs = new ArrayList<NameValuePair>();    
NameValuePair pair1 = new BasicNameValuePair("supervisor", supervisorEt.getEditableText().toString());  
NameValuePair pair2 = new BasicNameValuePair("content", superviseContentEt.getEditableText().toString()); 
NameValuePair pair3 = new BasicNameValuePair("userId", String.valueOf(signedUser.getId()));                    
pairs.add(pair1);  
pairs.add(pair2);  
pairs.add(pair3);                    
httpPost.setEntity(new UrlEncodedFormEntity(pairs, HTTP.UTF_8))  

二、StringEntity

JSONObject postData = new JSONObject();  
                  
postData.put("supervisor", supervisorEt.getEditableText().toString());  
postData.put("content", superviseContentEt.getEditableText().toString());  
postData.put("userId", signedUser.getId());  
                  
httpPost.setEntity(new StringEntity(postData.toString(), HTTP.UTF_8));

相关文章

网友评论

      本文标题:HttpPost 两种消息体形式 —— UrlEncodedFo

      本文链接:https://www.haomeiwen.com/subject/twkhfqtx.html