2015-09-27 71 views
0

HTttps请求不会在我的机器上为Android应用程序唤醒而HTTP正常工作。 我做了很多护目镜,但找不到成功。https请求不适用于android应用程序

公共静态字符串requestWithPostMethod(字符串URL,字符串jsonData) *抛出 * ClientProtocolException,IOException的 */{ // HttpURLConnection类的URLConnection;

String result = null; 
    try { 
     // Connect 

     URL newurl = new URL(url); 
     HttpURLConnection urlConnection = (HttpURLConnection) newurl.openConnection(); 
    // urlConnection = createConnection(url); 
     urlConnection.setRequestMethod("POST"); 
     urlConnection 
       .setRequestProperty("Content-Type", "application/json"); 
     urlConnection.setRequestProperty("Accept", "application/json"); 

     urlConnection.connect(); //here it return null exception 

     // Write 
     OutputStream outputStream = urlConnection.getOutputStream(); 
     BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
       outputStream, "UTF-8")); 
     writer.write(jsonData); 
     writer.close(); 
     outputStream.close(); 

     // Read 
     BufferedReader bufferedReader = new BufferedReader(
       new InputStreamReader(urlConnection.getInputStream(), 
         "UTF-8")); 

     String line = null; 
     StringBuilder sb = new StringBuilder(); 

     while ((line = bufferedReader.readLine()) != null) { 
      sb.append(line); 
     } 

     bufferedReader.close(); 

     // {"success":true,"result":[],"error":"","error_key":"email_validation_code"} 

     result = sb.toString(); 

    } catch (UnsupportedEncodingException e) { 
     if (e != null) { 
      e.printStackTrace(); 
     } 
    } catch (IOException e) { 
     if (e != null) { 
      e.printStackTrace(); 
     } 
    } 
    return result; 
} 

回答

1

这可能是服务器证书的问题。

相关问题