HttpClient httpclient1 = new DefaultHttpClient();
HttpParams p=new BasicHttpParams();
p.setParameter("vname",name);
p.setParameter("address", addr);
p.setParameter("age", age);
p.setParameter("contact", cnct);
p.setParameter("gender", gen);
p.setParameter("whomto", wtm);
p.setParameter("myFile", f);
HttpPost res1=new HttpPost(result);
res1.setHeader("Content-Type", "text/plain");
res1.setHeader("Content-Type","image/jpeg");
HttpResponse response1 = httpclient1.execute(res1);
HttpEntity entity1 = response1.getEntity();
i1 = entity1.getContent();
BufferedReader reader1 = new BufferedReader(new InputStreamReader(i1,"iso-8859-1"),8);
StringBuilder sb1 = new StringBuilder();
String line1 = null;
if((line1 = reader1.readLine()) != null) {
sb1.append(line1);
back=sb1.toString();
}
else{
Log.e("GET data","null");
}
i1.close();
Log.e("GET",""+back);
//服务器代码 private BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
public void doPost(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException {
res.setContentType("text/html");
Map<String, BlobKey> blobs = blobstoreService.getUploadedBlobs(req);
BlobKey blobKey = blobs.get("myFile");
final BlobInfo blobInfo = new BlobInfoFactory().loadBlobInfo(new BlobKey(blobKey.getKeyString()));
System.out.println(blobInfo.getContentType());
if(!blobInfo.getContentType().equalsIgnoreCase("image/jpeg")){
blobstoreService.delete(blobInfo.getBlobKey());
res.getWriter().println("Please Provide JPG image only");
}
我正在向服务器发送一个带有其他数据的图像文件。我没有收到任何错误或异常但是当我打印“返回”时,在日志中显示“此 URL 不接受请求的内容类型”。“f”是我的图像文件..有什么问题?