2013-02-05 53 views
5

मैं वर्तमान में उनके वर्तमान एपीआई v3 का उपयोग कर imgur को अपलोड करने की कोशिश कर रहा हूँ का उपयोग कर v3 imgur के लिए, फिर भी मैं त्रुटि प्राप्त हो रहीअपलोडिंग जावा https त्रुटियों

error: javax.net.ssl.SSLException: hostname in certificate didn't match: api.imgur.com != imgur.com OR imgur.com

त्रुटि है सुंदर आत्म explaintory इसलिए मैंने सोचा कि मैं इसके बजाय http का उपयोग करने का प्रयास करेंगे, लेकिन मुझे imgur के साथ त्रुटि कोड 400 मिल जाएगा। मुझे यकीन नहीं है कि इसका मतलब है कि मैं अपलोड करने का प्रयास कैसे कर रहा हूं, गलत है या अगर इम्गुर को SSL कनेक्शन पसंद नहीं हैं।

public String Imgur (String imageDir, String clientID) { 
    //create needed strings 
    String address = "https://api.imgur.com/3/image"; 

    //Create HTTPClient and post 
    HttpClient client = new DefaultHttpClient(); 
    HttpPost post = new HttpPost(address); 

    //create base64 image 
    BufferedImage image = null; 
    File file = new File(imageDir); 

    try { 
     //read image 
     image = ImageIO.read(file); 
     ByteArrayOutputStream byteArray = new ByteArrayOutputStream(); 
     ImageIO.write(image, "png", byteArray); 
     byte[] byteImage = byteArray.toByteArray(); 
     String dataImage = new Base64().encodeAsString(byteImage); 

     //add header 
     post.addHeader("Authorization", "Client-ID" + clientID); 
     //add image 
     List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1); 
     nameValuePairs.add(new BasicNameValuePair("image", dataImage)); 
     post.setEntity(new UrlEncodedFormEntity(nameValuePairs)); 

     //execute 
     HttpResponse response = client.execute(post); 

     //read response 
     BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); 
     String all = null; 

     //loop through response 
     while (rd.readLine() != null) { 
      all = all + " : " + rd.readLine(); 
     } 

     return all; 

    } 
    catch (Exception e){ 
     return "error: " + e.toString(); 
    } 
} 

मुझे आशा है कि किसी को या तो ऊपर कोड में त्रुटि खोजने या कैसे वर्तमान HTTPS इस मुद्दे को ठीक करने के लिए, धन्यवाद समझाने में मदद कर सकते हैं:

नीचे कोड की मेरी मॉड्यूल Imgur से कनेक्ट कर रहा है।

+0

क्या आपको कभी इसका जवाब मिला? मुझे वास्तव में यह पता लगाने की जरूरत है कि यह कैसे करना है, और अपना स्वयं का SSLFactory बनाना या तो काम नहीं करता है। –

उत्तर

4

ऐसा लगता है कि प्रमाणपत्र में डोमेन नाम उस डोमेन नाम से मेल नहीं खाता है जिसे आप एक्सेस कर रहे हैं, इसलिए एसएसएल अपेक्षित रूप से विफल रहा है। आप प्रमाणपत्र समस्या को अनदेखा करने के लिए HttpClient को बता सकते हैं और बस कनेक्शन स्थापित कर सकते हैं। विवरण के लिए यह stackoverflow answer देखें।

+0

यह समस्या बन गई, लेकिन मैंने इसे यहां जवाब का उपयोग करके हल किया: http://stackoverflow.com/questions/3135679/android-httpclient-hostname-in-certificate-didnt-match-example-com-ex । मैं अब के लिए बक्षीस से बचना होगा, लेकिन एक उथल-पुथल दूंगा। –