如何使用 volley (android) 向 ip 地址发送 POST 请求
How to send a POST request to ip address with volley (android)
如何使用 volley 将字符串请求发送到特定的 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 而不是服务器 URL http://test.me/api/request/page
我该怎么做?
Volley 是一个 Http 库。您不能使用 Volley 对 ip-address 和端口进行这样的调用。参见 this。
如何使用 volley 将字符串请求发送到特定的 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 而不是服务器 URL http://test.me/api/request/page
我该怎么做?
Volley 是一个 Http 库。您不能使用 Volley 对 ip-address 和端口进行这样的调用。参见 this。