我试图在post请求中发送一个csv文件,并希望在服务器端获取csv数据。我正在使用service.what创建web,在发送csv文件时应该是内容类型,在服务器端应该使用__注释。
泽西码
@POST
@Consumes("text/plain")
@Produces("text/plain")
public String respondToPost(String incomingCsv) throws IOException {
return incomingCsv;
}csv文件:
email,group_email
member1@visheshapps.uni.me,team3@visheshapps.uni.me
member2@visheshapps.uni.me,team3@visheshapps.uni.me这将返回:
----0246824681357ACXZabcxyz
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Content-Transfer-Encoding: 8bit
Content-ID: <startpart>
Content-Disposition: form-data; name="root-fields"
----0246824681357ACXZabcxyz
Content-Type: application/vnd.ms-excel
Content-Transfer-Encoding: binary
Content-ID: <group.csv>
Content-Disposition: attachment; name="file attachment"; filename="group.csv"
email,group_email
member1@visheshapps.uni.me,team3@visheshapps.uni.me
member2@visheshapps.uni.me,team3@visheshapps.uni.me
----0246824681357ACXZabcxyz--而我只想要
email,group_email
member1@visheshapps.uni.me,team3@visheshapps.uni.me
member2@visheshapps.uni.me,team3@visheshapps.uni.me我更改了代码,但现在我得到415个不受支持的媒体type.my应用程序托管在google应用程序引擎上。
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces("text/plain")
public String respondToPost(@FormDataParam("file") InputStream csv) throws IOException {
CSVReader csvReader = new CSVReader(new InputStreamReader(csv));
List<String[]> rows = csvReader.readAll();
return rows.get(1)[0];
}发布于 2012-05-22 06:40:54
您可以使用text\plain mediatype来接收请求,使用OpenCSV来解析请求体。
https://stackoverflow.com/questions/10696909
复制相似问题