android http post请求 restful,如何向RESTful webservice发送HttpPost请求以传递包含值数组参数的URL?...

我正在尝试调用RESTful webservice来获取JSON对象。现在我试着通过HttpGet进行通话并且成功了。我需要通过的URL非常类似于:http://example.com/ /def.xxx?Name=save &代码=示例& OrderDetails = [{“Count”:“2”,“ID”:“1”,“Price”: “5”}]。我如何向RESTful webservice发送HttpPost请求以传递包含值数组参数的URL?

`

StringBuilder URL = new StringBuilder("http://example.com/def.xxx?");

URL.append("Name="+name+"&");

URL.append("Code="+code+"&");

URL.append("Details=%5b");

int val = 0;

for (int i = 0; i

if (val > 0)

{URL.append(",");

}

else

val = 1;

URL.append(.....);

URLX = URL.toString();

httpGet = new HttpGet(URLX);

response = client1.execute(httpGet);

`

现在,如果我想使HttpPost调用,而不是HTTPGET的叫什么,应该怎么办?我想用这种方式,

String URL = "http://example.com/def.xxx";

DefaultHttpClient client1 = new DefaultHttpClient();

HttpResponse response = null;

HttpPost httpPost = new HttpPost();

ArrayList postParameters;

postParameters = new ArrayList();

postParameters.add(new BasicNameValuePair("Name", name));

postParameters.add(new BasicNameValuePair("Code", code));

try {

httpPost.setEntity(new UrlEncodedFormEntity(postParameters));

} catch (UnsupportedEncodingException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

}

response = client1.execute(httpPost);

} 现在我不知道我应该如何在详细信息中添加值对= [{“计数”:“2”,“ID”:“1”,“价格“:”5“}]在Post调用中,我应该如何执行它以获取与获取HttpGet时所获得的JSON对象相同的对象。请帮忙。

2013-06-24

MSIslam

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值