Java Apache HttpClient上传文件时出错(Java Apache HttpClient error uploading files)
我想使用HttpClient 4.3.1上传文件。 我需要添加以形成多部分输入流(以控制上载进度。)而不是File对象。 这是我的代码:
byte[] dump = ...; HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(SENDLOG_URL); MultipartEntityBuilder meb = MultipartEntityBuilder.create(); meb.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); // THIS WORKS!! meb.addBinaryBody("log", new File("C:\\temp.zip"), ContentType.APPLICATION_OCTET_STREAM,"log.zip"); InputStream is=new FileInputStream("C:\\temp.zip") meb.addBinaryBody("log", is, ContentType.DEFAULT_BINARY, "log.zip"); httppost.setEntity(meb.build()); HttpResponse resp=httpclient.execute(httppost); is.close();
使用方法MultipartEntityBuilder.addBinaryBody(Strin,File)它可以工作,但是使用MultipartEntityBuilder.addBinaryBody(Strin,InputStream)它不起作用。
java客户端不会抛出任何错误,但这是远程服务器(Apache)的答案:
HTTP / 1.1 400错误请求 [日期:星期四,2013年11月28日09:46:08 GMT,服务器:Apache / 2.4.6(Unix)mod_fcgid / 2.3.7,内容长度:226,连接:关闭,内容类型:text / html; 字符集= ISO-8859-1]
为什么新的File()和新的FileInputStream()之间存在这种奇怪的行为?
I want to upload a file using HttpClient 4.3.1. I need to add to form multipart an inputstream (to control upload progress.) instead of a File object. This is my code:
byte[] dump = ...; HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(SENDLOG_URL); MultipartEntityBuilder meb = MultipartEntityBuilder.create(); meb.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); // THIS WORKS!! meb.addBinaryBody("log", new File("C:\\temp.zip"), ContentType.APPLICATION_OCTET_STREAM,"log.zip"); InputStream is=new FileInputStream("C:\\temp.zip") meb.addBinaryBody("log", is, ContentType.DEFAULT_BINARY, "log.zip"); httppost.setEntity(meb.build()); HttpResponse resp=httpclient.execute(httppost); is.close();
Using the method MultipartEntityBuilder.addBinaryBody(Strin,File) it works, but using MultipartEntityBuilder.addBinaryBody(Strin,InputStream) it doesn't work.
The java client doesn't throw any error, but this is the answer of remote server (Apache):
HTTP/1.1 400 Bad Request [Date: Thu, 28 Nov 2013 09:46:08 GMT, Server: Apache/2.4.6 (Unix) mod_fcgid/2.3.7, Content-Length: 226, Connection: close, Content-Type: text/html; charset=iso-8859-1]
Why this strange behaviour between new File() and new FileInputStream()?
原文:https://stackoverflow.com/questions/20262769
满意答案
你需要一个OUTTER JOIN,这可以通过简单地添加
.DefaultIfEmpty()
来完成。from a in context.Module_Articles_Articles join c in context.Module_Articles_Categories on a.CategoryID equals c.CategoryID into ca from c in cs.DefaultIfEmpty() join co in context.Module_Articles_Comments on a.ArticleID equals co.ArticleID into com from co in com.DefaultIfEmpty() where a.IsDraft == false orderby a.ArticleID descending select new ...
you want an OUTTER JOIN, which can be accomplished in a query like this by simply adding
.DefaultIfEmpty()
from a in context.Module_Articles_Articles join c in context.Module_Articles_Categories on a.CategoryID equals c.CategoryID into ca from c in cs.DefaultIfEmpty() join co in context.Module_Articles_Comments on a.ArticleID equals co.ArticleID into com from co in com.DefaultIfEmpty() where a.IsDraft == false orderby a.ArticleID descending select new ...
相关问答
更多空表上的LEFT JOIN结果为NULL(LEFT JOIN on empty table NULLs results)
JOIN EACH没有返回结果(JOIN EACH not returning result)
SQL Join问题,如果第二个表为空则返回null(SQL Join question, return null if second table is empty)
LINQ如果第二个或第三个表为空,则加入不返回结果(LINQ Join not returning results if second or third table empty)
如何加入并获得4个结果(How to join and get 4 results)
从第二个表返回不同的值时连接表(Join tables while returning distinct values from the second table)
内部联接返回没有结果(Inner Join returning no results)
SUM表中的值,该表通过第三个表链接到第二个表(SUM a value from a table which is linked to a second table via a third table)
RIGHT JOIN返回所有NULL结果(RIGHT JOIN is returning all NULL results)
MySQL内连接不返回结果(MySQL inner join not returning results)
相关文章
更多HttpClient 上传文件
Hadoop Java程序-files功能测试
httpclient get请求
HttpClient DELETE请求示例
HttpClient PUT请求示例
flume写入Hadoop hdfs报错 Too many open files
httpClient快速入门
httpclient post 请求
HttpClient CacheConfig缓存处理示例
httpclient 带参数 get 请求
最新问答
更多获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
如何通过引用返回对象?(How is returning an object by reference possible?)
矩阵如何存储在内存中?(How are matrices stored in memory?)
每个请求的Java新会话?(Java New Session For Each Request?)
css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
xcode语法颜色编码解释?(xcode syntax color coding explained?)
在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!