When an image is uploaded, the above error is reported. However, the image has an address, the URL address is correct, but the image has an address. This means the image cannot be uploaded, and the breakpoint returns 404. when an image is uploaded, the above error is reported. However, the image has an address, the URL address is correct, but the image has an address. This means the image cannot be uploaded, and the breakpoint returns 404.
Reply content:
When an image is uploaded, the above error is reported. However, the image has an address, the URL address is correct, but the image has an address. This means the image cannot be uploaded, and the breakpoint returns 404.
404 description is client issues cause the server to be unable to handle, https://segmentfault.com/a/11...
We recommend that you discard httpclient and use 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 extends mrequest (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 cocould not be retrieved. // Signal to the caller that something was wrong with the connection. throw new IOException ("cocould 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
Call: String response = HttpConnector. javasmrequest (uploadUrl, file, null );