gpt4 book ai didi

android - (Android) D/OkHttp : 400 Bad Request

转载 作者:行者123 更新时间:2023-11-30 00:38:48 25 4
gpt4 key购买 nike

@Headers("Authorization: " + BuildConfig.CLIENT_ID + " " + BuildConfig.CLIENT_SECRET)
@GET("get/list")
Observable<List<Post>> getList();

在 get 文件夹中你可以找到这样的 .htaccess:

RewriteEngine On
AuthName "Staff Only:3"
AuthType Basic
AuthUserFile .../api/get/.htpasswd
require valid-user

Get/list 返回帖子的 json 数组。该 php 代码中没有 400 代码。我也确定在我的 json 响应中,它是正确的(由 jsonschema2pojo.org 确认)Header(codeblock 1) 真的授权我。

还有……

D/OkHttp: --> GET http://*********/api/get/list http/1.1
D/OkHttp: Authorization: r*******m *******6
D/OkHttp: --> END GET
...
D/OkHttp: <-- 400 Bad Request http://*********/api/get/list (18711ms)
D/OkHttp: Date: Sun, 19 Mar 2017 20:13:11 GMT
D/OkHttp: Content-Type: text/html
D/OkHttp: Content-Length: 177
D/OkHttp: Connection: close
D/OkHttp: Server: -nginx
D/OkHttp: CF-RAY: -
D/OkHttp: <html>
D/OkHttp: <head><title>400 Bad Request</title></head>
D/OkHttp: <body bgcolor="white">
D/OkHttp: <center><h1>400 Bad Request</h1></center>
D/OkHttp: <hr><center>cloudflare-nginx</center>
D/OkHttp: </body>
D/OkHttp: </html>
D/OkHttp: <-- END HTTP (177-byte body)

什么?为什么?请告诉我有什么问题?你能帮我解决这个问题吗?

最佳答案

您的 PHP 文件返回 Content-Type: text/html 而不是 Content-Type: application/json;charset=UTF-8,这就是您得到 400 的原因。在您的 PHP 文件上设置 header 。

header("Content-Type: application/json;charset=utf-8");

来自 PHP documentation :

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include, or require, functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.

关于android - (Android) D/OkHttp : 400 Bad Request,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42903191/

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