繁体   English   中英

如何使用Volley将POST请求发送到IP地址(Android)

[英]How to send a POST request to ip address with volley (android)

您如何使用凌空将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

我将如何去做呢?

Volley是一个Http库。 您不能使用Volley向IP地址和端口发出这样的呼叫。 看到这个

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM