您好,欢迎访问一九零五行业门户网

上传图片了就会报org.apache.http.client.HttpResponseException: Not Foun

一上传图片就会报上面的错, 的错,但是图片有地址,url的地址是对的但是有图片有地址的,就是上不去,断点返回的是404.
回复内容: 一上传图片就会报上面的错, 的错,但是图片有地址,url的地址是对的但是有图片有地址的,就是上不去,断点返回的是404.
404说明是客户端的问题导致服务器无法处理,https://segmentfault.com/a/11...
建议弃用httpclient,使用httpurlconnection:
import java.io.bytearrayoutputstream;import java.io.dataoutputstream;import java.io.file;import java.io.fileinputstream;import java.io.ioexception;import java.io.inputstream;import java.net.httpurlconnection;import java.net.url;import java.util.hashmap;import java.util.list;import java.util.map;public class httpconnector { public static final int timeout_ms = 10 * 1000; public static string performrequest(string url, file file, map additionalheaders) { string response = null; try { hashmap map = new hashmap(); if (additionalheaders != null) map.putall(additionalheaders); url parsedurl = new url(url); httpurlconnection connection = openconnection(parsedurl, file); for (string headername : map.keyset()) { connection.addrequestproperty(headername, map.get(headername)); } int responsecode = connection.getresponsecode(); if (responsecode == -1) { // -1 is returned by getresponsecode() if the response code could not be retrieved. // signal to the caller that something was wrong with the connection. throw new ioexception(could not retrieve response code from httpurlconnection.); } string charset = utf-8; string contentencoding = null; string contenttype = null; for (map.entry> header : connection.getheaderfields().entryset()) { if (header.getkey() != null) { list headervaluelist = header.getvalue(); if (headervaluelist != null && headervaluelist.size() > 0) { stringbuffer headervaluesb = new stringbuffer(); for (int i = 0; i
调用:string response = httpconnector.performrequest(uploadurl, file, null);
其它类似信息

推荐信息