这是主线程异常的os网络错误..我如何解决!?? 我正在使用localhost服务器 在许可我活跃,仍然没有工作
public void GetText() throws UnsupportedEncodingException{
String email = mEmailView.getText().toString();
String password = mPasswordView.getText().toString();
//urlTest = "http://localhost/php/projectsirius-the-rgstr/backoffice/login.php&id="+email;
String data = URLEncoder.encode("email", "UTF-8")
+ "=" + URLEncoder.encode(email, "UTF-8");
data += "&" + URLEncoder.encode("pass", "UTF-8")
+ "=" + URLEncoder.encode(password, "UTF-8");
String text = "";
BufferedReader reader=null;
try
{
URL url = new URL("http://localhost/php/projectsirius-the-rgstr/backoffice/test.php");
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write( data );
wr.flush();
// Get the server response
reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
StringBuilder sb = new StringBuilder();
String line = null;
// Read Server Response
while((line = reader.readLine()) != null)
{
// Append server response in string
sb.append(line + "\n");
}
text = sb.toString();
}
catch(Exception e)
{
Log.e("error","ERROR" + e.toString());
}
finally
{
try
{
reader.close();
}
catch(Exception ex) {}
}
// Show response on activity
content.setText( text );
}
答案 0 :(得分:0)
在此块中运行您的代码我试过了
Thread thread = new Thread(new Runnable(){
@Override
public void run() {
try {
//Your code goes here
} catch (Exception e) {
e.printStackTrace();
}
}
});
thread.start();