我正在尝试使用帖子将数据发送到 Web 服务器,这就是我目前所拥有的:
private void entity(String id, String file)
throws JSONException, UnsupportedEncodingException, FileNotFoundException {
// Add your data
File myFile = new File(
Environment.getExternalStorageDirectory(), file);
InputStreamEntity reqEntity = new InputStreamEntity(
new FileInputStream(myFile), myFile.length());
reqEntity.setContentType("text/csv");
reqEntity.setChunked(true); // Send in multiple parts if needed
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
nameValuePairs.add(new BasicNameValuePair("project", id));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
httppost.setEntity(reqEntity);
//httppost.setHeader("Content-Length", String.valueOf(myFile.length()));
}
当我发送发布请求时,它会返回所需的内容长度,但这不是在这里设置的吗?
InputStreamEntity reqEntity = new InputStreamEntity(
new FileInputStream(myFile), myFile.length());
不知道我做的对不对,请帮忙,谢谢
编辑 -
当我尝试自己设置内容长度时
httppost.setHeader("Content-Length", String.valueOf(myFile.length()));
它回来时已经设置了标题。
因此为什么它被注释掉了