【问题标题】:How to httpPost() to covert httpGet()?如何将 httpPost() 转换为 httpGet()?
【发布时间】:2013-04-19 05:49:30
【问题描述】:

这里是 httpPost() java 类,

public String getXmlFromUrl_NewRegistration(String url,
        String username, String firstname, String lastname, String email,
        String password) {
    String json = null;

    try {
        // defaultHttpClient

        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost("http://aleedex.biz/game/users.php?action=new");
        String postParameter = "username=" + username + "&firstname="
                + firstname + "&lastname=" + lastname + "&email=" + email
                + "&password=" + password;

        try {
            httpPost.setEntity(new StringEntity(postParameter));
        } catch (Exception e) {

        }

        HttpResponse httpResponse = httpClient.execute(httpPost);
        HttpEntity httpEntity = httpResponse.getEntity();
        json = EntityUtils.toString(httpEntity);

    } catch (UnsupportedEncodingException e) {

    } catch (ClientProtocolException e) {

    } catch (IOException e) {

        json = null;
    }

    Log.d("json", json);


    return json;
}

在 httpGet() 中也使用相同的参数,例如用户名、名字、姓氏、电子邮件、密码 如何通过 httpGet() 在该链接上使用相同的参数注册用户http://aleedex.biz/game/users.php?action=new

【问题讨论】:

  • 也许这是不好的做法,但您可以将所有这些信息放在 Http Header 中,并使用 SSL 或 TLS 加密连接。
  • 它怎么不能把信息放在http头中的任何例子
  • 我为你使用了谷歌:stackoverflow.com/questions/12358045/…
  • 谢谢你为我奋斗

标签: android json http http-post http-get


【解决方案1】:

在这里,您可以将帖子参数附加到 url,然后进行调用,它可以正常工作

`HttpGet _getrequest=new HttpGet("http://aleedex.biz/game/users.php? action=new&"+postParameter); 

 HttpResponse httpResponse = httpClient.execute(_getrequest);
    HttpEntity httpEntity = httpResponse.getEntity();
    json = EntityUtils.toString(httpEntity);`

试试这个,我觉得应该可以。

【讨论】:

  • 这对我没有帮助
  • 你想要的正是你想要的 HttpGet 请求
  • 是的,同样的参数只是把httppost改成httpget我是怎么做到的?
【解决方案2】:

我已经按照该教程解决了我的问题How to connect Android with PHP, MySQL

【讨论】:

    猜你喜欢
    • 2011-11-06
    • 1970-01-01
    • 1970-01-01
    • 2023-03-15
    • 2013-05-29
    • 1970-01-01
    • 1970-01-01
    • 2021-07-29
    • 1970-01-01
    相关资源
    最近更新 更多