How to httpPost() to covert httpGet()?

点点圈 提交于 2019-12-24 11:43:19

问题


The httpPost() java class here,

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;
}

Also use same parameters in httpGet(), like username, firstname, lastname, email, password how to register the user through httpGet() with same parameters on that link http://aleedex.biz/game/users.php?action=new


回答1:


here you can append the post parameters to the url and then make a call it works that it

`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);`

Try this i think this should work.




回答2:


I have follow that Tutorial and solve my problem How to connect Android with PHP, MySQL



来源:https://stackoverflow.com/questions/16098040/how-to-httppost-to-covert-httpget

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!