{"name" => "lorem", "description" => "ipsum"} 对于我的 RoR 网络服务 我的代码:-6ren">
gpt4 book ai didi

android - 使用 Android 创建高级 http 实体

转载 作者:可可西里 更新时间:2023-11-01 16:35:05 24 4
gpt4 key购买 nike

我需要像这样创建一个 httpentiy:

"project" => {"name" => "lorem", "description" => "ipsum"} 

对于我的 RoR 网络服务

我的代码:

    private String postData(String url, String user, String password, ArrayList<NameValuePair> nameValuePairs) throws ClientProtocolException, IOException
{
HttpPost httppost = new HttpPost(url);
HttpClient httpclient = this.getDefaultHttpClient(20000, user, password);
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse r = httpclient.execute(httppost);

return inputStreamToString(r.getEntity().getContent());
}

这让我只能做这样的事情:

"name" => "lorem", "description" => "ipsum"

有没有人有一个干净的解决方案?

最佳答案

希望这能解决您的问题...

List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("project[name]", "Dinash"));
nameValuePairs.add(new BasicNameValuePair("project[description]", "dina"));

关于android - 使用 Android 创建高级 http 实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6187788/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com