尝试构建httpget链接时出现URISyntaxException

时间:2013-04-09 11:25:36

标签: java android base64 http-get

尝试执行以下操作时,我收到了URISyntaxException异常。我完全不知道是什么造成了这个问题。得到一些帮助会很高兴。错误位于最后一行

    EditText edUserName = (EditText)findViewById(R.id.textBox_username_register);
    String strUsernameTemp = edUserName.getText().toString();
    byte[] byteUsernameTemp = null;
    try
    {
        byteUsernameTemp = strUsernameTemp.getBytes("UTF-8");
    }
    catch(UnsupportedEncodingException e)
    {
        e.printStackTrace();
    }
    String strUsername = Base64.encodeToString(byteUsernameTemp, Base64.DEFAULT);

    EditText edPassword = (EditText)findViewById(R.id.passwordBox_password_register);
    String strPasswordTemp = edPassword.getText().toString();
    byte[] bytePasswordTemp = null;     
    try
    {
        bytePasswordTemp = strPasswordTemp.getBytes("UTF-8");
    }
    catch(UnsupportedEncodingException e)
    {
        e.printStackTrace();
    }
    String strPassword = Base64.encodeToString(bytePasswordTemp, Base64.DEFAULT);       

    EditText edEmail = (EditText)findViewById(R.id.textBox_email_register);
    String strEmailTemp = edEmail.getText().toString();
    byte[] byteEmailTemp = null;
    try
    {
        byteEmailTemp = strEmailTemp.getBytes("UTF-8");
    }
    catch(UnsupportedEncodingException e)
    {
        e.printStackTrace();
    }       
    String strEmail = Base64.encodeToString(byteEmailTemp, Base64.DEFAULT);     

    String strD = "22";
    String strM = "11";
    String strY = "1993";
    StringBuilder builder = new StringBuilder();
    HttpClient client = new DefaultHttpClient();        
    HttpGet httpget = new HttpGet(loginData.strAPIURL + "addUser&username=" + strUsername + "&password=" + strPassword + "&email=" + strEmail + "&d=" + strD + "&m=" + strM + "&y=" + strY); // this line causes the error

1 个答案:

答案 0 :(得分:0)

如果在创建URI时无法解析某些信息,则通常会抛出

URISyntaxException。尝试使用URI对您的URLEncoder进行编码。

String encodedURI = java.net.URLEncoder.encode(loginData.strAPIURL + "addUser&username=" + strUsername + "&password=" + strPassword + "&email=" + strEmail + "&d=" + strD + "&m=" + strM + "&y=" + strY,"UTF-8");
HttpGet httpget = new HttpGet(encodedURI);