Java 我怎样才能在第二节中发布消息?
此项目使用Java 我怎样才能在第二节中发布消息?,java,android,json,retrofit2,Java,Android,Json,Retrofit2,此项目使用web服务器运行。当用户单击按钮时,它应该在EditText中发布消息。我使用2进行改装。当我单击按钮时,程序已停止 ApiInterface.java @POST("api/EmergencyNotification/SendNotification") Call<SendMessageModel>postMessage(@Header("Authorization") String token, // @F
web服务器运行。当用户单击按钮时,它应该在EditText
中发布消息。我使用2
进行改装。当我单击按钮时,程序已停止
ApiInterface.java
@POST("api/EmergencyNotification/SendNotification")
Call<SendMessageModel>postMessage(@Header("Authorization") String token,
// @Field(("PhotoRequest")) String photoRequest,
// @Field(("Location")) String location,
@Field(("MessageBody")) String messageBody);
// @Field(("AnswerValue")) String answerValue);
您缺少@FormUrlEncoded
属性,因为您使用的是字段属性而不是正文
@POST("api/EmergencyNotification/SendNotification")
@FormUrlEncoded
Call<SendMessageModel>postMessage(@Header("Authorization") String token,
...
@POST(“api/EmergencyNotification/SendNotification”)
@FormUrlEncoded
CallpostMessage(@Header(“Authorization”)字符串标记,
...
好的。我现在解决了。我的api url错误,我添加了新的@Multipart
和@Part
,而不是@Field
@POST("api/EmergencyNotification/SendMessage")
Call<SendMessageModel>postMessage(@Header("Authorization") String token,
@Part(("MessageBody")) String messageBody);
@POST(“api/EmergencyNotification/SendMessage”)
CallpostMessage(@Header(“Authorization”)字符串标记,
@部分((“MessageBody”))字符串MessageBody);
您的API是表单数据或JSON请求?它是表单数据。它不起作用。这是邮递员中的表单数据。不是表单URL编码。然后不要使用字段属性,使用@Body(“MessageBody”)String messageBody
我会尝试。通常情况下,我必须发送位置和照片。因此,我使用字段。我现在只尝试首先发送消息。所以我将它们设置为注释行。当我使用@Body时,messageBody中有错误,它说找不到方法“value”。
@POST("api/EmergencyNotification/SendMessage")
Call<SendMessageModel>postMessage(@Header("Authorization") String token,
@Part(("MessageBody")) String messageBody);