URLEncoder无法翻译“)”(括号)字符

时间:2016-05-18 16:36:58

标签: android

我正在向服务器发送Json请求。并且Url具有括号字符。

我收到错误意外的响应代码500
this.editorWebBrowser.Document.AttachEventHandler("ondblclick", (_object, _event) =>
        {
            //First check if the user has selected something, if not, move the current selection starting from the current location of the text cursor.
            if (string.IsNullOrEmpty(SelectedText.Trim()))
            {
                //All objects bellow are referenced, there is no need to assign them to the HtmlEditorControl again
                // define the selected range object
                mshtml.IHTMLSelectionObject selection;
                mshtml.IHTMLTxtRangerange = null;
                try
                {
                    // calculate the text range based on user selection
                    selection = _mshtmlDocument.selection;

                    if (selection.type.ToLower().Equals("text") || selection.type.ToLower().Equals("none"))
                    {
                        range = (mshtml.IHTMLTxtRange)selection.createRange();
                    }
                }
                catch (Exception)
                {
                    // have unknown error so set return to null
                    range = null;
                    return;
                }

                if (range == null)
                {
                    //error!!
                    return;
                }

                //Move the current selection one word back
                range.moveStart("word", -1);
                range.moveEnd("word", 1);
                range.select();
                if (range.text == null)
                {
                    //error!!
                    return;
                }
            }
        });

开始Bracket字符url结束的地方。我认为编码不能正常工作

请求

 Unexpected response code 500 for http://admin.unimax.kz/api/Klientapi?login=+7(707)930-00-66&password=123456

此处:login =“+ 7(707)123-45-67”
pass =“123456”

1 个答案:

答案 0 :(得分:2)

我建议首先创建查询部分URL并使用以下方法对其进行编码: URLEncoder

示例:

String query = "?login=" + URLEncoder.encode(login, "UTF-8") + "&password="+ URLEncoder.encode(pass, "UTF-8");
String url = REGISTER_URL + query;