404连接到套接字的错误请求错误

时间:2017-09-27 14:52:32

标签: java android sockets http-status-code-400

我希望在连接和登录参数作为查询参数发送之前连接到需要登录的一个套接字。

要与套接字连接,我正在使用此库 - https://medium.com/@ssaurel/learn-to-use-websockets-on-android-with-okhttp-ba5f00aea988

这适用于他们的演示套接字,但我无法连接到我的套接字。

JavaScript中的Web代码看起来像

socket : io.connect('52.11.67.123:6060', { query: {user:JSON.stringify({user:usercus}) ,login:JSON.stringify({username:'esw',password:'escrust'})}}),

某些库用于连接套接字并发送查询参数。

在android中发送查询参数我尝试使用Uri.Builder,我将url与客户端url相匹配,但是我无法连接它。

代码:

 private void start() {

    try {

        Uri.Builder builder = new Uri.Builder();
        builder.scheme("ws")
                .encodedAuthority("52.11.67.123:6060")
                .appendEncodedPath("socket.io/")
                .appendQueryParameter("user", "{\"user\":{\"customer_id\":\"10\",\"customer_group_id\":\"0\",\"password\":\"81dc9bdb52d04dc20036dbd8313ed055\",\"first_name\":\"iykeone\",\"last_name\":\"Idukpaye\",\"email\":\"iykeidukpaye@gmail.com\",\"address\":\"30\",\"is_company\":\"1\",\"photo\":\"upload/1504896445753.png\",\"business_type\":\"test\",\"ip\":\"\",\"customer_unique_id\":\"271113lq034225\",\"status\":\"0\",\"date_added\":\"2013-11-27 03:42:25\",\"date_login\":\"2016-10-04 09:22:47\",\"online_status\":\"0\",\"is_forget_password\":\"0\",\"customer_add\":\"\",\"phonecode\":\"0\",\"phonecode1\":\"0\",\"phonecode2\":\"0\",\"customer_phone\":\"0\",\"business_info\":\"\",\"bank_ac\":\"012102102\",\"bank_name\":\"bfbdbfsb\",\"routing_no\":\"7895464\",\"bank_address\":\"iykeidukpaye@yahoo.com\",\"bank_country\":\"8\",\"bank_ac_type\":\"current\",\"bank_ac_name\":\"IykeIdukpaye\",\"bank_ac_address1\":\"Test Test Test Test Test Test Test Test Test Test Test Teest Test Test Test Test Test Test Test Test Test Test Test Test\",\"bank_ac_address2\":\"Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test\",\"dr_cr_card\":\"Mc\",\"purpose_code\":\"CONSULTING\",\"confirmation_code\":\"\",\"dispatcher\":\"1\",\"dispatch_plan\":\"5\",\"dispatcher_id\":\"TDP10LDI\",\"dispatcher_location\":\"[\\\"Local\\\",\\\"Domestic\\\",\\\"International\\\"]\",\"merchant\":\"5\",\"verify\":\"0\",\"customer_phone1\":\"0\",\"customer_phone2\":\"0\",\"verify1\":\"0\",\"verify2\":\"0\",\"dispatch_status\":\"0\",\"dispatch_limit\":\"34800\",\"Ratings\":\"0\",\"deviceNotificationToken\":null,\"bankname\":\"ANTARCTICA\"}}")
                .appendQueryParameter("login", "{\"username\":\"escw\",\"password\":\"escst\"}");

        String myUrl = builder.build().toString()+"&EIO=3&transport=websocket&sid=voy5xrGfTWNs6nSFAAAr";
    //    String myUrl = builder.build().toString();
        Log.e("socket:",myUrl);

        Request request = new Request.Builder().url(myUrl).build();
        EchoWebSocketListener listener = new EchoWebSocketListener();
        WebSocket ws = client.newWebSocket(request, listener);

        client.dispatcher().executorService().shutdown();

    }
    catch (JSONException je)
    {

    }
}
private void output(final String txt) {
    runOnUiThread(new Runnable() {
        @Override
        public void run() {

            Log.d("response",txt);
            Toast.makeText(MainActivity.this, txt,Toast.LENGTH_LONG).show();
        }
    });
}

客户端网址如下所示:

 ws://52.11.67.123:6060/socket.io/?user=%7B%22user%22%3A%7B%22customer_id%22%3A%2210%22%2C%22customer_group_id%22%3A%220%22%2C%22password%22%3A%2281dc9bdb52d04dc20036dbd8313ed055%22%2C%22first_name%22%3A%22iykeone%22%2C%22last_name%22%3A%22Idukpaye%22%2C%22email%22%3A%22iykeidukpaye%40gmail.com%22%2C%22address%22%3A%2230%22%2C%22is_company%22%3A%221%22%2C%22photo%22%3A%22upload%2F1504896445753.png%22%2C%22business_type%22%3A%22test%22%2C%22ip%22%3A%22%22%2C%22customer_unique_id%22%3A%22271113lq034225%22%2C%22status%22%3A%220%22%2C%22date_added%22%3A%222013-11-27%2003%3A42%3A25%22%2C%22date_login%22%3A%222016-10-04%2009%3A22%3A47%22%2C%22online_status%22%3A%220%22%2C%22is_forget_password%22%3A%220%22%2C%22customer_add%22%3A%22%22%2C%22phonecode%22%3A%220%22%2C%22phonecode1%22%3A%220%22%2C%22phonecode2%22%3A%220%22%2C%22customer_phone%22%3A%220%22%2C%22business_info%22%3A%22%22%2C%22bank_ac%22%3A%22012102102%22%2C%22bank_name%22%3A%22bfbdbfsb%22%2C%22routing_no%22%3A%227895464%22%2C%22bank_address%22%3A%22iykeidukpaye%40yahoo.com%22%2C%22bank_country%22%3A%228%22%2C%22bank_ac_type%22%3A%22current%22%2C%22bank_ac_name%22%3A%22IykeIdukpaye%22%2C%22bank_ac_address1%22%3A%22Test%20Test%20%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Teest%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%22%2C%22bank_ac_address2%22%3A%22Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%22%2C%22dr_cr_card%22%3A%22Mc%22%2C%22purpose_code%22%3A%22CONSULTING%22%2C%22confirmation_code%22%3A%22%22%2C%22dispatcher%22%3A%221%22%2C%22dispatch_plan%22%3A%225%22%2C%22dispatcher_id%22%3A%22TDP10LDI%22%2C%22dispatcher_location%22%3A%22%5B%5C%22Local%5C%22%2C%5C%22Domestic%5C%22%2C%5C%22International%5C%22%5D%22%2C%22merchant%22%3A%225%22%2C%22verify%22%3A%220%22%2C%22customer_phone1%22%3A%220%22%2C%22customer_phone2%22%3A%220%22%2C%22verify1%22%3A%220%22%2C%22verify2%22%3A%220%22%2C%22dispatch_status%22%3A%220%22%2C%22dispatch_limit%22%3A%2234800%22%2C%22Ratings%22%3A%220%22%2C%22deviceNotificationToken%22%3Anull%2C%22bankname%22%3A%22ANTARCTICA%22%7D%7D&login=%7B%22username%22%3A%22escw%22%2C%22password%22%3A%22escrndtrust%22%7D&EIO=3&transport=websocket&sid=voy5xrGfTWNs6nSFAAAr

我的网址看起来像这样:

ws://52.11.67.123:6060/socket.io/?user=%7B%22user%22%3A%7B%22customer_group_id%22%3A%220%22%2C%22customer_unique_id%22%3A%22271113lq034225%22%2C%22bank_name%22%3A%22bfbdbfsb%22%2C%22dispatch_plan%22%3A%225%22%2C%22verify2%22%3A%220%22%2C%22verify%22%3A%220%22%2C%22verify1%22%3A%220%22%2C%22customer_phone%22%3A%220%22%2C%22date_login%22%3A%222016-10-04%2009%3A22%3A47%22%2C%22password%22%3A%2281dc9bdb52d04dc20036dbd8313ed055%22%2C%22dispatcher%22%3A%221%22%2C%22bank_ac_type%22%3A%22current%22%2C%22dr_cr_card%22%3A%22Mc%22%2C%22routing_no%22%3A%227895464%22%2C%22is_forget_password%22%3A%220%22%2C%22first_name%22%3A%22iykeone%22%2C%22purpose_code%22%3A%22CONSULTING%22%2C%22bank_ac_address1%22%3A%22Test%20Test%20%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Teest%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%22%2C%22date_added%22%3A%222013-11-27%2003%3A42%3A25%22%2C%22phonecode%22%3A%220%22%2C%22dispatcher_location%22%3A%22%5B%5C%22Local%5C%22%2C%5C%22Domestic%5C%22%2C%5C%22International%5C%22%5D%22%2C%22bank_ac_address2%22%3A%22Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%20Test%22%2C%22bank_country%22%3A%228%22%2C%22bank_address%22%3A%22iykeidukpaye%40yahoo.com%22%2C%22phonecode2%22%3A%220%22%2C%22phonecode1%22%3A%220%22%2C%22customer_add%22%3A%22%22%2C%22online_status%22%3A%220%22%2C%22customer_phone1%22%3A%220%22%2C%22customer_phone2%22%3A%220%22%2C%22bankname%22%3A%22ANTARCTICA%22%2C%22merchant%22%3A%225%22%2C%22bank_ac%22%3A%22012102102%22%2C%22status%22%3A%220%22%2C%22Ratings%22%3A%220%22%2C%22confirmation_code%22%3A%22%22%2C%22business_info%22%3A%22%22%2C%22dispatcher_id%22%3A%22TDP10LDI%22%2C%22dispatch_status%22%3A%220%22%2C%22bank_ac_name%22%3A%22IykeIdukpaye%22%2C%22photo%22%3A%22upload%5C%2F1504896445753.png%22%2C%22ip%22%3A%22%22%2C%22address%22%3A%2230%22%2C%22email%22%3A%22iykeidukpaye%40gmail.com%22%2C%22is_company%22%3A%221%22%2C%22last_name%22%3A%22Idukpaye%22%2C%22dispatch_limit%22%3A%2234800%22%2C%22business_type%22%3A%22test%22%2C%22customer_id%22%3A%2210%22%7D%7D&login=%7B%22username%22%20%3A%20%22esw%22%2C%22password%22%20%3A%20%22esrowtrust%22%7D&EIO=3&transport=websocket&sid=voy5xrGfTWNs6nSFAAAr

我不明白为什么没有连接。 错误是:

错误:预期的HTTP 101响应但是'400 Bad Request'

如何使用查询参数连接套接字? 请帮忙。谢谢..

0 个答案:

没有答案