如何正确写@POST请求?
How to write a @POST request correctly?
我正在尝试提出 @POST
请求。当我提出这个要求时
@POST("/testAPI")
@Headers("token: rAhUCUo-wz-Sbtwjt1")
@FormUrlEncoded
Call<GetEntires> getEntires(@Field("a")String method,
@Field("session")String SessionId);
我得到响应:HTML 站点代码 API,但是当我在特殊程序(是 Chrome 应用程序 - ARC)中发出请求时,我得到了正确的响应,这等于 API 文档的响应。
来自 API:
文档的请求示例
curl --header "token: EXAMPLETOKEN" --data "a=new_session" https://bnet.i-partner.ru/testAPI/
我在哪里弄错了?
更新:
来自应用程序 ARC 的文本请求的外观:
POST /testAPI/ HTTP/1.1
HOST: bnet.i-partner.ru
token: rAhUCUo-wz-Sbtwjt1
content-type: multipart/form-data; boundary=----WebKitFormBoundaryLA3TDEc7BbGOFNMS
content-length: 256
------WebKitFormBoundaryLA3TDEc7BbGOFNMS
Content-Disposition: form-data; name="a"
get_entries
------WebKitFormBoundaryLA3TDEc7BbGOFNMS
Content-Disposition: form-data; name="session "
tThEPaP7uvGWje176p
------WebKitFormBoundaryLA3TDEc7BbGOFNMS--
来自服务器的响应:
{
"status": 1,
"data": [
[],
],
}
对我来说,它有效:
@Multipart
@POST("/testAPI")
fun createPost(@Part("a") post: String?,
@Part("session") post2: String?): Call<Post?>?
我用了@Part
我正在尝试提出 @POST
请求。当我提出这个要求时
@POST("/testAPI")
@Headers("token: rAhUCUo-wz-Sbtwjt1")
@FormUrlEncoded
Call<GetEntires> getEntires(@Field("a")String method,
@Field("session")String SessionId);
我得到响应:HTML 站点代码 API,但是当我在特殊程序(是 Chrome 应用程序 - ARC)中发出请求时,我得到了正确的响应,这等于 API 文档的响应。 来自 API:
文档的请求示例curl --header "token: EXAMPLETOKEN" --data "a=new_session" https://bnet.i-partner.ru/testAPI/
我在哪里弄错了?
更新: 来自应用程序 ARC 的文本请求的外观:
POST /testAPI/ HTTP/1.1
HOST: bnet.i-partner.ru
token: rAhUCUo-wz-Sbtwjt1
content-type: multipart/form-data; boundary=----WebKitFormBoundaryLA3TDEc7BbGOFNMS
content-length: 256
------WebKitFormBoundaryLA3TDEc7BbGOFNMS
Content-Disposition: form-data; name="a"
get_entries
------WebKitFormBoundaryLA3TDEc7BbGOFNMS
Content-Disposition: form-data; name="session "
tThEPaP7uvGWje176p
------WebKitFormBoundaryLA3TDEc7BbGOFNMS--
来自服务器的响应:
{
"status": 1,
"data": [
[],
],
}
对我来说,它有效:
@Multipart
@POST("/testAPI")
fun createPost(@Part("a") post: String?,
@Part("session") post2: String?): Call<Post?>?
我用了@Part