改造1,发送带有自定义按键多形式的数据值
我使用的是API
这是在我的掌握,以及已经加入了一个开发团队最近正在使用Retrofit1
。改造1,发送带有自定义按键多形式的数据值
我无法将请求发送到需要的格式服务器,因为服务器需要多形式的数据体的格式如下:
Uniqueidentifier:FileName.jpg:ReroutServerIP:Base64EncodedDocString.
我已经为了做到这一点尝试了许多不同的技术任务,但我找不到任何工作方法来做到这一点。服务器告诉我消息格式不受支持。这是我目前的代码(去掉了网址)。请有人协助?
@POST("URL")
public Response post_SendData(@Header("Content-Type") String ContentType, @Body String body);
为了达到理想的效果,我可以使用没有标题的邮递员,并使用form-data post方法从我的系统发布文件。在工作邮差帖子中,密钥是上面提到的格式化字符串,值是从我的桌面上选择的文件。请看下面的邮递员(编辑删除网址)。
非常感谢球员。
如果你想将文件发送到服务器:
public void uploadPictureRetrofit(File file, Callback<YourObject> response) {
// this will build full path of API url where we want to send data.
RestAdapter restAdapter = new RestAdapter
.Builder()
.setEndpoint(YOUR_BASE_URL)
.setConverter(new SimpleXMLConverter()) // if the response is an xml
.setLogLevel(RestAdapter.LogLevel.FULL)
.build();
// SubmitAPI is name of our interface which will send data to server.
SendMediaApiInterface api = restAdapter.
create(SendMediaApiInterface.class);
TypedFile typedFile = new TypedFile(MULTIPART_FORM_DATA, file);
api.sendImage(typedFile, response);
}
这是接口SendMediaApiInterface:
public interface SendMediaApiInterface {
@Multipart
@POST("url")
void sendImage(@Part("here_is_the_attribute_name_in_webservice") TypedFile attachments, Callback<YourObject> response);}
我认为这与我所需要的很接近,唯一的问题是每次都需要指定@Part名称,因为唯一标识符对用户是唯一的。你知道我能做到这一点吗? –
例如,如果** ** here_is_the_attribute_name_in_webservice = ** “image_attribute” ** 你的API网址将是这样的:http://base_ur_example.com/upload_photo_example?image_attribute= 请检查您的API,并填写相应的attribut –
我编辑过这个帖子,也许我问的是错误的问题? –
你要一个多文件发送到服务器吗? –
的确,但他们有一个非常奇怪的格式,我必须遵守。 –
我编辑了这篇文章,包括我已经能够得到这个工作的唯一方法(使用邮差)。 –