When an image is uploaded, org. apache. http. client. HttpResponseException: NotFoun will be reported.

Source: Internet
Author: User
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 );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.