gpt4 book ai didi

android - HttpUrlConnection.connect 抛出异常

转载 作者:行者123 更新时间:2023-11-29 01:29:54 26 4
gpt4 key购买 nike

<分区>

在 AndroidStudio 中开发,我有以下代码来连接服务器并将一些数据发布到服务器:

try {
EditText et = (EditText)findViewById(R.id.friend);
EditText et2 = (EditText)findViewById(R.id.name);
HashMap<String,String> hm = new HashMap<>();
hm.put("name", et2.getText().toString());
hm.put("friend_name", et.getText().toString());
URL url = new URL("http://wwtbamandroid.appspot.com/rest/friends");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("POST");
con.setDoOutput(true);
con.connect();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(con.getOutputStream(), "UTF-8"));
writer.write(getPostDataString(hm));
writer.flush();
writer.close();
}
catch (Exception e){
Log.e("Error", "Connection error -> "+e.getMessage());}

并且在 con.connect(); 行抛出异常我不明白为什么,我找不到错误。谢谢你的帮助

这是我的日志:

08-02 21:15:07.798  16864-16864/? I/art﹕ Late-enabling -Xcheck:jni
08-02 21:15:08.070 16864-16881/android.josema.whowantstobeamillionaire I/art﹕ Background partial concurrent mark sweep GC freed 187(24KB) AllocSpace objects, 0(0B) LOS objects, 31% free, 35MB/51MB, paused 6.048ms total 24.693ms
08-02 21:15:08.091 16864-16897/android.josema.whowantstobeamillionaire D/OpenGLRenderer﹕ Use EGL_SWAP_BEHAVIOR_PRESERVED: true
08-02 21:15:08.096 16864-16864/android.josema.whowantstobeamillionaire D/Atlas﹕ Validating map...
08-02 21:15:08.149 16864-16897/android.josema.whowantstobeamillionaire I/Adreno-EGL﹕ <qeglDrvAPI_eglInitialize:379>: QUALCOMM Build: 01/14/15, ab0075f, Id3510ff6dc
08-02 21:15:08.150 16864-16897/android.josema.whowantstobeamillionaire I/OpenGLRenderer﹕ Initialized EGL, version 1.4
08-02 21:15:08.163 16864-16897/android.josema.whowantstobeamillionaire D/OpenGLRenderer﹕ Enabling debug mode 0
08-02 21:15:15.181 16864-16864/android.josema.whowantstobeamillionaire
E/Error﹕ Connection error -> null

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