多个实体(自定义对象)设置为HTT prequest [英] set multiple entity ( custom object ) to httpRequest

查看:162
本文介绍了多个实体(自定义对象)设置为HTT prequest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

List<NameValuePair> nvps = new ArrayList<NameValuePair>();
nvps.add(new BasicNameValuePair("Provider", "UY"));
nvps.add(new BasicNameValuePair("AccessToken ", "sdfl;kjsdg"));

httpPost.setEntity(new UrlEncodedFormEntity(nvps));

我添加参数,这样的HTTP请求。
但我怎么能增加一个实体,是一个java.util.Dictionary中的对象。

I am adding parameter to http request like this. But how can I add another Entity which is a java.util.Dictionary object.

Dictionary<String, String) dict = new Dictionary();
//add values to dict

httpPost.setEntity(dict); 

将不起作用。什么是应该做的正确的方式?

will not work. What is the right way to do?

更新

这是我的服务器要求

 Dictionary ExtraData 

 string Provider 

 string AccessToken 

两个字符串值,我可以为列表与下发;&的NameValuePair GT; nvps 。并将其设置为实体。但如何对第一个?

The two String values I can send as List<NameValuePair> nvps. and set it to entity. but how about the first one?

阅读,我不能多实体设置为HTT prequest

Read that I cannot set multiple entity to httpRequest

推荐答案

您可以将您的字典对象转换为JSON。然后,你就可以张贴字典对象的字符串就像你正在做。

You can convert your dictionary object to a json. Then you'll be able to post the dictionary object as string like you're currently doing.

不完全的答案,但我确实是这样。

Not exactly the answer you wanted, but I do it this way.

这篇关于多个实体(自定义对象)设置为HTT prequest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆