gpt4 book ai didi

java - 我们可以使用 volley 库在删除请求中发送带有 x-www-url-form-encoded 的正文吗?

转载 作者:行者123 更新时间:2023-12-02 13:27:18 24 4
gpt4 key购买 nike

如何在android中发送x-www-form-urlencoded中的数据来传递删除请求?

@Override
public byte[] getBody() {

Map<String, String> params = new HashMap<>();
params.put("is_admin","1");
params.put("client_dbname",sessionManager.clientdbname());
params.put("user_id" ,"1");

//yeah, I copied this from the base method.
if (params !=null)
{
try {
para = params.toString().getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}

return para;
}

最佳答案

这是因为 Volley 默认情况下不发送正文进行 DELETE。仅适用于 POST、PUT 和 PATCH。

使用此第三方进行删除请求

https://github.com/ngocchung/DeleteRequest

尝试使用此类进行删除请求:

public class StringJSONBodyReqest extends StringRequest {

private static final String TAG = StringJSONBodyReqest.class.getName();
private final String mContent;

public StringJSONBodyReqest(int method, String url, String content, Response.Listener<String> listener, Response.ErrorListener errorListener) {
super(method, url, listener, errorListener);
mContent = content;
}


@Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("api-version", "1");

return headers;
}


@Override
public byte[] getBody() throws AuthFailureError {

byte[] body = new byte[0];
try {
body = mContent.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
Log.e(TAG, "Unable to gets bytes from JSON", e.fillInStackTrace());
}
return body;
}


@Override
public String getBodyContentType() {
return "application/json";
}
}

关于java - 我们可以使用 volley 库在删除请求中发送带有 x-www-url-form-encoded 的正文吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43338627/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com