gpt4 book ai didi

java - Android 截击 : Cannot pass data to server

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

我正在尝试为我的 Android 应用程序创建一个简单的注册页面。我使用 URL 字符串传递参数并将这些参数存储在数据库中。每当我尝试直接在浏览器中使用字符串时,数据都会添加到数据库中,不会出现任何错误。但是,当我尝试从 Android Volley 传递数据时,我收到 HTTP 错误 409。

我已经检查了所有内容,但仍然很困惑为什么只有当我尝试从 Android 应用程序运行 url 字符串时才会出现此错误。

URL 字符串:-

http://myurl.com/api/register.php?name=ahmed&email=obaid.ahmed@gmail.com&password=12345&membertype=Artist&joindate=24-Feb-2019

Java 代码:-

       JsonObjectRequest getRequest = new JsonObjectRequest(Request.Method.GET, urlFinal, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
// display response
Log.d("Response", response.toString());
uploadImageToServer();
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.d("Error.Response", error.toString());
hideDialog();
}
}
);

最佳答案

首先你需要了解409,

在这里解释一下:- https://httpstatuses.com/409

并尝试在发生此冲突问题的服务器端解决此问题。

我建议您在 url 中发送内容之前使用 URL 编码,其执行者:要么通过,

  String query = URLEncoder.encode("apples oranges", "utf-8");
String url = "http://stackoverflow.com/search?q=" + query;

或由

  String uri = Uri.parse("http://...")
.buildUpon()
.appendQueryParameter("key", "val")
.build().toString();

这使您的网址更加兼容。

或者为了获得更多更好的方法,我个人向所有喜欢轻量级 Volley for Api Integrations 的 Android 开发人员推荐一个库。

https://github.com/Lib-Jamun/Volley

dependencies {
compile 'tk.jamun:volley:0.0.4'
}

酷编码。

关于java - Android 截击 : Cannot pass data to server,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54845654/

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