Questions tagged «androidhttpclient»

12
用Android发出HTTP请求
我到处搜索,但找不到答案,有没有办法发出简单的HTTP请求?我想在我的一个网站上请求一个PHP页面/脚本,但是我不想显示该页面。 如果可能的话,我什至想在后台(在BroadcastReceiver中)进行操作

10
使用Retrofit 2.0的POST多部分表单数据,包括图像
我正在尝试使用Retrofit 2.0对服务器进行HTTP POST MediaType MEDIA_TYPE_TEXT = MediaType.parse("text/plain"); MediaType MEDIA_TYPE_IMAGE = MediaType.parse("image/*"); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); imageBitmap.compress(Bitmap.CompressFormat.JPEG,90,byteArrayOutputStream); profilePictureByte = byteArrayOutputStream.toByteArray(); Call<APIResults> call = ServiceAPI.updateProfile( RequestBody.create(MEDIA_TYPE_TEXT, emailString), RequestBody.create(MEDIA_TYPE_IMAGE, profilePictureByte)); call.enqueue(); 服务器返回错误,指出文件无效。 这很奇怪,因为我尝试在iOS上以相同的格式上传相同的文件(使用其他库),但是上传成功。 我想知道使用Retrofit 2.0上传图像的正确方法是什么? 上传之前,我应该先将其保存到磁盘吗? PS:我已经对其他不包含图像的Multipart请求进行了改造,并且已成功完成。问题是当我尝试向身体包括一个字节时。
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.