【问题标题】:How to send a POST request to ip address with volley (android)如何使用 volley (android) 向 IP 地址发送 POST 请求
【发布时间】:2017-06-30 12:36:16
【问题描述】:

如何使用 volley 将 stringrequest 发送到特定的 ip 地址和端口而不是 url?

我的代码目前如下所示:

public void onURLPassed(final String urlOfWebsite) {

    Log.d(TAG, "Url passed: " + urlOfWebsite);

    String tag_json_obj = "json_obj_req";

    String serverURL = "http://test.me/api/request/page";

    StringRequest jsonObjReq = new StringRequest(Request.Method.POST,
            serverURL,
            new Response.Listener<String>() {

                @Override
                public void onResponse(String response) {
                    Log.d(TAG, response);
                    String parsedResponse = parse(response); 
                    if (parsedResponse.equals("Error: This is not a valid website")) { 
                        if (isViewAttached()) {
                            getView().displayMessage("This is not a valid website");
                        } else {
                            // error handling
                        }
                        return;
                    }
                    parsedResponse = parsedResponse.replace("\\" + "n", "  \n");
                    parsedResponse = parsedResponse.replace("\\" + "\"", "\"");
                    getView().displayWebsite(parsedResponse.substring(1, parsedResponse.length()-1));
                }
            }, new Response.ErrorListener() {

我现在要做的是将相同的 POST 请求发送到例如 12.123.12.123:40 而不是 serverURL http://test.me/api/request/page

我该怎么做呢?

【问题讨论】:

标签: android ip port android-volley webrequest


【解决方案1】:

Volley 是一个 Http 库。您不能使用 Volley 对 ip 地址和端口进行这样的调用。见this

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-10
    • 2013-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多