gpt4 book ai didi

java - 响应状态代码::404 改造 2.0

转载 作者:行者123 更新时间:2023-12-01 18:02:07 26 4
gpt4 key购买 nike

据我了解,我遇到这个问题是因为我的代码有问题,但我可以找到确切的原因

这是我的代码

public class MainActivity extends AppCompatActivity {

private MyServerConnection connection;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

String URL = ...;
final Retrofit retrofit = new Retrofit.Builder()
.baseUrl(URL)
.addConverterFactory(GsonConverterFactory.create())
.build();

connection = retrofit.create(MyServerConnection.class);

}

interface MyServerConnection {
@POST("/appreg")
Call<JSONObject> postWithJson(@Body JSONObject object);
}

public void test(View view) {
Log.e("TAG", "---!!! TEST !!!---");

final Call<JSONObject> call = connection.postWithJson(getJson());
call.enqueue(new Callback<JSONObject>() {
@Override
public void onResponse(Call<JSONObject> call, Response<JSONObject> response) {
Log.e("Response status code: ", String.valueOf(response.code()));

// isSuccess is true if response code => 200 and <= 300
if (response.isSuccessful()) {
Log.e("response body : ", response.body().toString());
} else {
try {
Log.e("response body error : ", response.errorBody().string());

here i get NULL ---> Log.e("!!!-- response body : ", " " + response.body());

} catch (IOException ignored) {
}
}
}

@Override
public void onFailure(Call<JSONObject> call, Throwable t) {
Log.e("TAG", "---!!! ERROR !!!--- : " + t.getMessage());
}
});
}

private JSONObject getJson() {
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("key", "val");
} catch (JSONException e) {
e.printStackTrace();
}
return jsonObject;
}

我收到这样的错误消息

E/response body error :: <!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Page not found at /appreg</title>
<meta name="robots" content="NONE,NOARCHIVE">
<style type="text/css">
html * { padding:0; margin:0; }
body * { padding:10px 20px; }
body * * { padding:0; }
body { font:small sans-serif; background:#eee; }
body>div { border-bottom:1px solid #ddd; }
h1 { font-weight:normal; margin-bottom:.4em; }
h1 span { font-size:60%; color:#666; font-weight:normal; }
table { border:none; border-collapse: collapse; width:100%; }
td, th { vertical-align:top; padding:2px 3px; }
th { width:12em; text-align:right; color:#666; padding-right:.5em; }
#info { background:#f6f6f6; }
#info ol { margin: 0.5em 4em; }
#info ol li { font-family: monospace; }
#summary { background: #ffc; }
#explanation { background:#eee; border-bottom: 0px none; }
</style>
</head>
<body>
<div id="summary">
<h1>Page not found <span>(404)</span></h1>
<table class="meta">
<tr>
<th>Request Method:</th>
<td>POST</td>
</tr>
<tr>
<th>Request URL:</th>
<td>http://52.58.65.214:3030/appreg</td>
</tr>

</table>
</div>
<div id="info">

<p>
Using the URLconf defined in <code>APIGW.urls</code>,
Django tried these URL patterns, in this order:
</p>
<ol>

<li>




^gcm/


</li>

<li>

^web/


</li>

<li>

^app/


</li>

</ol>
<p>The current URL, <code>appreg</code>, didn't match any of these.</p>

</div>

<div id="explanation">
<p>
You're seeing this error because you have <code>DEBUG = True</code> in
your Django settings file. Change that to <code>False</code>, and Django
will display a standard 404 page.
</p>
</div>
</body>
</html>

这很奇怪,因为如果我在浏览器中输入 URL,我会检索标准响应

{ "data": null, "service": null, "status": { "code": 1, "description": "An error occurs while processing your request, Please try later or contact our sales department", "status": "success" } }

我如何才能通过我的应用程序获得相同的标准消息?

我做错了什么?

最佳答案

最终我发现了我的情况的原因是由于 /

我把这个/放在.baseUrl(URL)中的URL末尾,并且我把它放在方法@POST("/appreg")...

当我从这样的方法中删除它时 @POST("appreg") 它开始工作

关于java - 响应状态代码::404 改造 2.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40125500/

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