gpt4 book ai didi

java - Android HttpPost javax.net.ssl.SSLProtocolException 无法识别的名称

转载 作者:太空宇宙 更新时间:2023-11-03 14:55:44 28 4
gpt4 key购买 nike

我正尝试从 Android 平板电脑向 api 发布一些数据,但我不断收到 SSLProtocolException,我无法找出问题所在。

这是我不断收到的错误:

javax.net.ssl.SSLHandshakeException: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0x7bccbdc8: Failure in SSL library, usually a protocol error
error:14077458:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 unrecognized name (external/openssl/ssl/s23_clnt.c:741 0x73d67718:0x00000000)
W/System.err﹕ at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:468)
W/System.err﹕ at com.android.org.conscrypt.OpenSSLSocketImpl$SSLInputStream.<init>(OpenSSLSocketImpl.java:717)
W/System.err﹕ at com.android.org.conscrypt.OpenSSLSocketImpl.getInputStream(OpenSSLSocketImpl.java:688)
W/System.err﹕ at org.apache.http.impl.io.SocketInputBuffer.<init>(SocketInputBuffer.java:70)
W/System.err﹕ at org.apache.http.impl.SocketHttpClientConnection.createSessionInputBuffer(SocketHttpClientConnection.java:83)
W/System.err﹕ at org.apache.http.impl.conn.DefaultClientConnection.createSessionInputBuffer(DefaultClientConnection.java:170)
W/System.err﹕ at org.apache.http.impl.SocketHttpClientConnection.bind(SocketHttpClientConnection.java:106)
W/System.err﹕ at org.apache.http.impl.conn.DefaultClientConnection.openCompleted(DefaultClientConnection.java:129)
W/System.err﹕ at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:221)
W/System.err﹕ at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:167)
W/System.err﹕ at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:125)
W/System.err﹕ at org.apache.http.impl.client.DefaultRequestDirector.executeOriginal(DefaultRequestDirector.java:1227)
W/System.err﹕ at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:677)
W/System.err﹕ at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
W/System.err﹕ at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
W/System.err﹕ at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
W/System.err﹕ at com.example.casper.bilfinger.sendJSONdata.doInBackground(sendJSONdata.java:130)
W/System.err﹕ at com.example.casper.bilfinger.sendJSONdata.doInBackground(sendJSONdata.java:54)
W/System.err﹕ at android.os.AsyncTask$2.call(AsyncTask.java:288)
W/System.err﹕ at java.util.concurrent.FutureTask.run(FutureTask.java:237)
W/System.err﹕ at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
W/System.err﹕ W/System.err﹕at java.lang.Thread.run(Thread.java:841)
W/System.err﹕ Caused by: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0x7bccbdc8: Failure in SSL library, usually a protocol error
W/System.err﹕ error:14077458:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 unrecognized name (external/openssl/ssl/s23_clnt.c:741 0x73d67718:0x00000000)
W/System.err﹕ W/System.err﹕at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
W/System.err﹕ W/System.err﹕at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:425)
W/System.err﹕ ... 23 more

这是我正在使用的代码。

public  class sendJSONdata extends AsyncTask<String, String, String>{

String httpAuthUser=*username*;
String httpAuthPassword=*password*;


String Bedrijf;
String Naam;
String Functie;
String Vestiging;
String Telefoonnummer;
String Email;
String Opmerkingen;
String GesprokenMet;
Context context;


@Override
protected void onPreExecute() {
super.onPreExecute();
}


public sendJSONdata(String[] values,Context context)
{
Bedrijf= values[0];
Naam= values[1];
Functie= values[2];
Vestiging= values[3];
Telefoonnummer= values[4];
Email= values[5];
Opmerkingen= values[6];
GesprokenMet= values[7];
this.context=context;
//System.setProperty("jsse.enableSNIExtension", "false");

}

protected String doInBackground(String... strings) {
///Build JSON object and fill with your data
JSONObject subpostMessage = new JSONObject();
try {
subpostMessage.put("emailAdres", Email);
subpostMessage.put("Naam", Naam);
subpostMessage.put("Bedrijfsnaam", Bedrijf);
subpostMessage.put("Telnummer", Telefoonnummer);
subpostMessage.put("Functie", Functie);
subpostMessage.put("Vestiging", Vestiging);
subpostMessage.put("Opmerkingen", Opmerkingen);
subpostMessage.put("GesprokenMet", GesprokenMet);
} catch (JSONException e) {
e.printStackTrace();
}

//Connect to HttpClient with basic Aut
HttpParams httpParameters = new BasicHttpParams();
HttpClient httpclient = new MyHttpClient(httpParameters,context);//new DefaultHttpClient(httpParameters);//
HttpPost httppost = new HttpPost(*Https to php file");
String base64EncodedCredentials = "Basic " + Base64.encodeToString((httpAuthUser + ":" + httpAuthPassword).getBytes(), Base64.NO_WRAP);
httppost.setHeader("Authorization", base64EncodedCredentials);

String responseStr = null;
try {
// Add your data to te connection
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("postData", subpostMessage.toString()));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

Log.d("httpPost: ",httppost.getMethod());
Log.d("ValuePairs- name: ",nameValuePairs.get(0).getName()+ " val: "+ nameValuePairs.get(0).getValue());

// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);

//Recover result response
responseStr = EntityUtils.toString(response.getEntity());

Log.d("JSON ATTEMPT","Response: "+responseStr);
} catch (ClientProtocolException e) {
Log.d("JSON ATTEMPT","Response:CPerror "+e.toString());
} catch (IOException e) {
Log.d("JSON ATTEMPT","Response:IOerror "+e.toString());
}
return responseStr;
}


protected void onPostExecute(String result) {
if (result == null) {
//Request Failed
return;
}

//System.out.println("RECEIVED RESPONSE: " + result);

try {
JSONObject jObj = new JSONObject(result);
} catch (JSONException e) {
e.printStackTrace();
}
}

@Override
protected void onProgressUpdate(String... values) {
}

}

还有它被调用的地方。

    void postJSONdata()
{
String[] values = new String[8];
values[0]=bnaam.getText().toString();
values[1]=naam.getText().toString();
values[2]=functie.getText().toString();
values[3]=vestiging.getText().toString();
values[4]=tele.getText().toString();
values[5]=mail.getText().toString();
values[6]=opmerking.getText().toString();
values[7]=gesprokenmet.getText().toString();
sendJSONdata task = new sendJSONdata(values,getApplicationContext());
task.execute();
}

这个错误在我尝试的任何 jdk 上抛出 (6,7,8),我发现的大多数帖子都表明它与 7 中引入的 SNI 有关,但对于 6 我仍然有同样的错误。

最佳答案

此问题是由服务器的配置以及客户端不支持或无效支持 SNI 引起的。如果没有使用 SNI 或者使用了错误的名称,服务器将返回 unrecognized_name 警报。因此,您需要确保使用支持 SNI 的 Java 版本,启用它并使用正确的名称访问服务器。

关于java - Android HttpPost javax.net.ssl.SSLProtocolException 无法识别的名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29604599/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com