如何httpPost()隐蔽HTTPGET()?(How to httpPost() to cove

2019-10-18 01:07发布

这里的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

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

试试这个,我认为这应该工作。



Answer 2:

我遵循教程和解决我的问题如何Android的使用PHP,MySQL连接



文章来源: How to httpPost() to covert httpGet()?