Hello All我正在向服务器发送注册数据但是我的代码行 dos = new DataOutputStream(urlConn.getOutputStream());遇到它抛出IOException“权限被拒绝” 我之前也使用了相同的代码用于另一台服务器,那时它工作正常。 我没有得到这个问题 请帮助我 我的代码是 尝试 {
URL url;
// URLConnection urlConn; DataOutputStream dos; DataInputStream dis;
/ ---------------------这是地址链接我们必须在哪里发送数据------------ *** /
String server_url_string =“http:----”signup.php“;
url = new URL(server_url_string);
// urlConn = url.openConnection(); HttpURLConnection urlConn =(HttpURLConnection)url.openConnection();
urlConn.setDoInput(true);
urlConn.setDoOutput(true);
urlConn.setUseCaches(false);
urlConn.setRequestProperty ("METHOD", "POST");
dos = new DataOutputStream (urlConn.getOutputStream());
/ * -------------准备在服务器上发送数据字符串----------------- - /
String data_to_be_send = "signupdata=first_name="+first_name_str+":"+
"oomplast_name="+last_name_str+":"+
"oomppassword="+password_str+":"+
"oompprimary_email="+email_str;
Log.i("SERVER URL ",server_url_string);
Log.i("SENDING DATA ",data_to_be_send);
dos.writeBytes(data_to_be_send);
dos.flush();
dos.close();
/ ** ------服务器通过说“注册成功”来回应。或“特定消息或无效数据”----- * /
/ -------------------从服务器中回复消息来源---------------- /
dis = new DataInputStream(urlConn.getInputStream());
Log.i(“PASSED”,“dis INITIALIZED”);
server_message = dis.readLine();
Log.i(“PASSED”,“server_message INITIALIZED”);
Log.i(“SERVER RESPONSE”,server_message +“”);
}
catch(MalformedURLException mue)
{
Log.i(“EXCEPTION GENERATED MalformedURLException”,“”+ mue.getMessage());
}
catch (IOException ioe)
{
Log.i("EXCEPTION GENERATED IOException ", " "+ioe.getMessage());
}
答案 0 :(得分:1)
确保Android Manifest中有<uses-permission android:name="android.permission.INTERNET"/>
。