1
我从来没有对Jsoup工作之前,现在我有一个项目,其中家伙用JSoup lib和我需要做一些重构,使同样的工作,但与retrofit2 ...转换Jsoup请求retrofit2
我坚持转换发送图像文件的请求。这里是原来的JSoup要求:
Connection.Response result = Jsoup.connect(apiURL + "sendImg/")
.method(Connection.Method.POST)
.header("Token", XCSRFToken)
.data("source", currentImage.getMD5().concat(".jpg"),
new FileInputStream(bitmapURI.getPath()))
.execute();
这里是我尝试用改装的事:
@Multipart
@POST("sendImg/")
Call<CbSendImage> sendImage(@Header("Token") String token, @Part MultipartBody.Part file);
public void sendImage(File file) {
RequestBody requestFile =
RequestBody.create(MediaType.parse("multipart/form-data"), file);
MultipartBody.Part body =
MultipartBody.Part.createFormData("source",
currentImage.getMD5().concat(".jpg"), requestFile);
mSendImageCall = mServerApi.sendImage(getToken(), body);
mSendImageCall.enqueue(sendImageCallback);
}
但仍然请求失败...
任何想法如何转换该请求是否正确?谢谢!