百度:javahttp客户端
而且上面已经写提示了...
no network security config specified using platform default
没有使用平台默认指定的网络安全配置
我替你放到百度翻译里翻译了
好像不是这个问题,因为我已经申明了网络权限,感觉是域名出错,但是不知道具体错在哪里
连不上服务器.你的模拟器.真的能连上服务器?上面写的很清楚.连接被拒绝.
问题找到了,是端口的问题,谢谢了!
端口设置有问题,导致访问服务器失败。
我也遇到了这个问题,能教教我吗?
什么问题
@寻求帮助的编程小白:
D/OpenGLRenderer: Swap behavior 0 W/IInputConnectionWrapper: finishComposingText on inactive InputConnection W/IInputConnectionWrapper: finishComposingText on inactive InputConnection W/IInputConnectionWrapper: finishComposingText on inactive InputConnection W/IInputConnectionWrapper: finishComposingText on inactive InputConnection D/NetworkSecurityConfig: No Network Security Config specified, using platform default D/StrictMode: StrictMode policy violation; ~duration=67 ms: android.os.StrictMode$StrictModeNetworkViolation: policy=65543 violation=4 at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1309) at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:333) at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:196)
@寻求帮助的编程小白:
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
@fliduck: 代码
@寻求帮助的编程小白:
1 package com.example.administrator.test_21; 2 3 import android.os.Message; 4 import android.os.StrictMode; 5 import android.support.v7.app.AppCompatActivity; 6 import android.os.Bundle; 7 import android.util.Log; 8 import android.view.View; 9 import android.widget.Button; 10 import android.widget.EditText; 11 import android.widget.TextView; 12 13 import java.io.BufferedReader; 14 import java.io.InputStreamReader; 15 import java.net.HttpURLConnection; 16 import java.net.URL; 17 import java.util.HashMap; 18 import java.util.Map; 19 20 public class MainActivity extends AppCompatActivity { 21 22 Button getBtn; 23 TextView txt; 24 EditText editname, editpsd, editemail; 25 26 @Override 27 protected void onCreate(Bundle savedInstanceState) { 28 super.onCreate(savedInstanceState); 29 setContentView(R.layout.activity_main); 30 getBtn=(Button)findViewById(R.id.button); 31 editpsd=(EditText)findViewById(R.id.editText); 32 editname=(EditText)findViewById(R.id.editText2); 33 editemail=(EditText)findViewById(R.id.editText3); 34 txt=(TextView)findViewById(R.id.textView2); 35 setVersion(); // 设置线程策略 ///////////////////// 36 getBtn.setOnClickListener(new mClick()); 37 } 38 39 class mClick implements View.OnClickListener 40 { 41 StringBuilder stringBuilder = new StringBuilder(); 42 BufferedReader buffer = null; 43 HttpURLConnection connGET = null; 44 @Override 45 public void onClick(View v) { 46 //获取界面文本框中的文字内容 47 String name=editname.getText().toString(); 48 String psd=editpsd.getText().toString(); 49 String email=editemail.getText().toString(); 50 try{ 51 String str="http://10.30.92.169/test/play-post.php?psd="+ 52 psd+"&name="+name+"&email="+email; 53 URL url = new URL(str); //构建Web服务器的url地址 54 connGET = (HttpURLConnection) url.openConnection(); 55 connGET.setConnectTimeout(5000); //设置超时的时间,5000毫秒即5秒 56 connGET.setRequestMethod("GET"); //设置获取数据的方式为GET 57 if ( connGET.getResponseCode() == 200) { 58 buffer = new BufferedReader(new InputStreamReader(connGET.getInputStream())); 59 for(String s = buffer.readLine();s != null; s = buffer.readLine()){ 60 stringBuilder.append(s); //构造字符串 61 } 62 txt.setText(stringBuilder); 63 buffer.close(); 64 } 65 } 66 catch(Exception e){ 67 e.printStackTrace(); 68 txt.setText("get 提交 err....."); 69 } 70 } 71 } 72 73 void setVersion() 74 { 75 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() 76 .detectDiskReads() 77 .detectDiskWrites() 78 .detectNetwork() // 这里可以替换为detectAll() 就包括了磁盘读写和网络I/O 79 .penaltyLog() //打印logcat,也可以定位到dropbox,通过文件保存相应的log 80 .build()); 81 } 82 }
@fliduck:申明权限了吗
@寻求帮助的编程小白: 有
1 <?xml version="1.0" encoding="utf-8"?> 2 <manifest xmlns:android="http://schemas.android.com/apk/res/android" 3 package="com.example.administrator.test_21"> 4 5 <application 6 android:allowBackup="true" 7 android:icon="@mipmap/ic_launcher" 8 android:label="@string/app_name" 9 android:supportsRtl="true" 10 android:theme="@style/AppTheme"> 11 <activity android:name=".MainActivity"> 12 <intent-filter> 13 <action android:name="android.intent.action.MAIN" /> 14 15 <category android:name="android.intent.category.LAUNCHER" /> 16 </intent-filter> 17 </activity> 18 </application> 19 <uses-permission android:name="android.permission.INTERNET"/> 20 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 21 <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> 22 23 </manifest>
@fliduck: 372176435讨论一下
@寻求帮助的编程小白: 加了