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 ...
相关问答
更多-
试试这个: SELECT alias.name alias, team.name team, sid.steam_id steam_id, (SUM(IFNULL(ws1.kills,0)) + SUM(IFNULL(ws2.kills,0)) + SUM(IFNULL(spnr.kills,0))) kills_total FROM pickup JOIN player ON player.pickup_id = pickup.id ...
-
JOIN EACH没有返回结果(JOIN EACH not returning result)[2021-07-21]
这是Firefox上BigQuery Web UI中的一个错误。 对长期工作的轮询工作不正常,因此任何超过2分钟的工作都表现出上述行为。 我们已经修复了这个错误,修复程序将在下周推出。 This was a bug in the BigQuery web UI on Firefox. Polling for long-running jobs was not working correctly, so any job that ran for more than 2 minutes exhibited th ... -
使用聚合函数(在这种情况下为AVG() )时,需要使用非聚合字段指定GROUP BY子句,例如 GROUP BY p.id, p.name 要确保所有project引用都存在,无论连接的等级如何,请使用LEFT JOIN 。 When using an aggregate function (AVG() in this case), you need to specify a GROUP BY clause with the non-aggregate fields, eg GROUP BY p.id, ...
-
LINQ如果第二个或第三个表为空,则加入不返回结果(LINQ Join not returning results if second or third table empty)[2023-08-28]
你需要一个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 o ... -
如何加入并获得4个结果(How to join and get 4 results)[2021-12-30]
你的问题似乎是在WHERE 。 这个说法: Select A.Artnr, A.grp, A.name, B.eigenschap, B.waarde from A left join B on B.Artnr = A.Artnr 会返回第3条,这是 3 FlowerC NameC NULL NULL 在此之后,您会筛选eigenschap = 'color' ,这会从最终结果集中移除该行,因为eigenschap为NULL 。 将该条件移至连接条件: Select A.Artn ... -
你得到的结果是正确的。 您正在获取列analyzeid和fileid的catersian product 。 您应该只select一列来避免这种情况。 但是,在连接表时尝试使用ANSI-SQL join语法: select t1.id , t1.name , t1.date , t1.analysisid , NULL as fileid from Table_1 t1 JOIN Table_2 t2 ON t2.id = t1.id and t2.name = t1.name and t2.date = ...
-
内部联接返回没有结果(Inner Join returning no results)[2020-02-01]
查询有一个错误,因为您的SELECT slug是不明确的。 您的列slug出现在所有表中,因此MySQL不知道要返回哪一列。 你需要这样做 SELECT `highlight_table`.`slug` from `highlight_table` 这将告诉MySQL只返回highlight_table的slug列。 然后你应该只获得1行蓝色,因为蓝色存在于所有三个表中。 更改为文章和用户表的LEFT JOIN将返回2个结果(绿色和蓝色),因为INNER JOIN基本上用作AND, LEFT JOIN更 ... -
SUM表中的值,该表通过第三个表链接到第二个表(SUM a value from a table which is linked to a second table via a third table)[2022-05-15]
您的查询逻辑非常接近。 你需要GROUP BY : SELECT sj.ID, SUM(c.Size) as Total_Size FROM Sub_Jobs sj INNER JOIN Cargo_Assignment ca ON ca.Sub_Job_ID = sj.ID INNER JOIN Cargo c ON c.ID = ca.Cargo_ID GROUP BY sj.ID; 请注意,您不需要JOIN到Sub_Jobs ,因为该字段位于Cargo_Ass ... -
我认为正确的加入应该是内联。 请尝试以下查询: SELECT vcc.name, vcc.quantity, vcc.custom_message, vfd.value FROM vxu_4_wpsc_cart_contents AS vcc INNER JOIN vxu_4_wpsc_submited_form_data as vfd ON vcc.purchaseid = vfd.log_id WHERE vfd.form_id IN ...
-
尝试这个: SELECT * FROM table1 t1 INNER JOIN table2 t2 ON (t1.name like CONCAT('%', trim(t2.Last_Name), '%') AND t1.name like CONCAT('%', trim(t2.First_Name), '%') ) Try this: SELECT * FROM table1 t1 INNER JOIN table2 t2 ...