- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想用我的应用程序连接到我所在大学的学生门户网站,并从该网站访问某些信息,例如当前成绩。所以到目前为止我已经写了这段代码我在登录时遇到了问题。每当我按下登录按钮时应用程序崩溃..我知道我的代码有问题所以如果你们帮我解决问题我将非常感激..在这里是我的学生资料的 url。
http://111.68.99.8/StudentProfile/
这是我到目前为止编写的代码......
java文件
package com.example.ebad.testing;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends ActionBarActivity {
Button login;
TextView Enrollement,password,E;
private static final String TAG = "MyActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Enrollement = (TextView) findViewById(R.id.Enrollment);
password = (TextView) findViewById(R.id.password);
login = (Button) findViewById(R.id.login_button);
E = (TextView) findViewById(R.id.message);
login.setOnClickListener(
new Button.OnClickListener() {
public void onClick(View v) {
String GMAIL_CONTACTS = "http://111.68.99.8/StudentProfile/PersonalInfo.aspx";
String GMAIL_LOGIN = "http://111.68.99.8/StudentProfile/";
String message_e = E.toString();
message_e += "";
String Enrollement_e = Enrollement.toString();
String password_e = password.toString();
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(GMAIL_LOGIN);
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(3);
nameValuePairs.add(new BasicNameValuePair("ctl00_Body_ENROLLMENTTextBox_tb", Enrollement_e));
nameValuePairs.add(new BasicNameValuePair("ctl00_Body_PasswordTextBox_tb", password_e));
nameValuePairs.add(new BasicNameValuePair("ctl00_Body_LoginButton", "login"));
try {
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
// Execute HTTP Post Request
HttpResponse response = null;
try {
response = httpClient.execute(httpPost);
} catch (IOException e) {
e.printStackTrace();
}
message_e +=response.getStatusLine();
E.setText(message_e);
Log.d(TAG, "response stat code " + response.getStatusLine().getStatusCode());
if (response.getStatusLine().getStatusCode() < 400) {
String cookie = response.getFirstHeader("Set-Cookie")
.getValue();
Log.d(TAG, "cookie: " + cookie);
// get the contacts page
HttpGet getContacts = new HttpGet(GMAIL_CONTACTS);
getContacts.setHeader("Cookie", cookie);
try {
response = httpClient.execute(getContacts);
} catch (IOException e) {
e.printStackTrace();
}
InputStream ins = null;
try {
ins = response.getEntity().getContent();
} catch (IOException e) {
e.printStackTrace();
}
BufferedReader in = new BufferedReader(new InputStreamReader(
ins));
String inputLine;
try {
while ((inputLine = in.readLine()) != null) {
Log.d(TAG, " " + inputLine);
}
} catch (IOException e) {
e.printStackTrace();
}
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
} else {
Log.d(TAG, "Response error: "
+ response.getStatusLine().getStatusCode());
}
}
}
);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
这是 xml 文件...
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter the Enrollement"
android:id="@+id/Enrollment"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="51dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/password"
android:hint="Enter the Password"
android:layout_marginTop="50dp"
android:layout_below="@+id/Enrollment"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="LOGIN"
android:id="@+id/login_button"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="38dp"
android:layout_marginEnd="38dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/message"
android:layout_below="@+id/login_button"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="82dp" />
</RelativeLayout>
Logcat 在这里
08-06 00:43:58.542 1904-1904/com.example.ebad.testing I/art﹕ Not late-enabling -Xcheck:jni (already on)
08-06 00:44:03.139 1904-1936/com.example.ebad.testing D/OpenGLRenderer﹕ Render dirty regions requested: true
08-06 00:44:03.142 1904-1904/com.example.ebad.testing D/﹕ HostConnection::get() New Host Connection established 0xa6c42500, tid 1904
08-06 00:44:03.203 1904-1904/com.example.ebad.testing D/Atlas﹕ Validating map...
08-06 00:44:03.473 1904-1917/com.example.ebad.testing I/art﹕ Background sticky concurrent mark sweep GC freed 3295(250KB) AllocSpace objects, 0(0B) LOS objects, 23% free, 872KB/1135KB, paused 39.997ms total 200.658ms
08-06 00:44:03.539 1904-1917/com.example.ebad.testing W/art﹕ Suspending all threads took: 66.163ms
08-06 00:44:03.821 1904-1911/com.example.ebad.testing W/art﹕ Suspending all threads took: 210.005ms
08-06 00:44:03.832 1904-1936/com.example.ebad.testing D/﹕ HostConnection::get() New Host Connection established 0xa6c42a30, tid 1936
08-06 00:44:03.838 1904-1917/com.example.ebad.testing I/art﹕ Background partial concurrent mark sweep GC freed 1888(102KB) AllocSpace objects, 0(0B) LOS objects, 55% free, 834KB/1858KB, paused 3.470ms total 295.680ms
08-06 00:44:03.892 1904-1936/com.example.ebad.testing I/OpenGLRenderer﹕ Initialized EGL, version 1.4
08-06 00:44:03.932 1904-1936/com.example.ebad.testing D/OpenGLRenderer﹕ Enabling debug mode 0
08-06 00:44:03.959 1904-1936/com.example.ebad.testing W/EGL_emulation﹕ eglSurfaceAttrib not implemented
08-06 00:44:03.959 1904-1936/com.example.ebad.testing W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xae1de500, error=EGL_SUCCESS
08-06 00:44:03.970 1904-1917/com.example.ebad.testing W/art﹕ Suspending all threads took: 132.060ms
08-06 00:44:04.215 1904-1904/com.example.ebad.testing I/Choreographer﹕ Skipped 38 frames! The application may be doing too much work on its main thread.
08-06 00:44:04.823 1904-1904/com.example.ebad.testing I/Choreographer﹕ Skipped 36 frames! The application may be doing too much work on its main thread.
08-06 00:44:05.503 1904-1936/com.example.ebad.testing W/EGL_emulation﹕ eglSurfaceAttrib not implemented
08-06 00:44:05.503 1904-1936/com.example.ebad.testing W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xae1de500, error=EGL_SUCCESS
08-06 00:44:24.394 1904-1911/com.example.ebad.testing W/art﹕ Suspending all threads took: 5.553ms
08-06 00:45:10.805 1904-1904/com.example.ebad.testing W/System.err﹕ org.apache.http.conn.HttpHostConnectException: Connection to http://111.68.99.8 refused
08-06 00:45:10.805 1904-1904/com.example.ebad.testing W/System.err﹕ at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:183)
08-06 00:45:10.805 1904-1904/com.example.ebad.testing W/System.err﹕ at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
08-06 00:45:10.805 1904-1904/com.example.ebad.testing W/System.err﹕ at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
08-06 00:45:10.805 1904-1904/com.example.ebad.testing W/System.err﹕ at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
08-06 00:45:10.805 1904-1904/com.example.ebad.testing W/System.err﹕ at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
08-06 00:45:10.806 1904-1904/com.example.ebad.testing W/System.err﹕ at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
08-06 00:45:10.806 1904-1904/com.example.ebad.testing W/System.err﹕ at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
08-06 00:45:10.806 1904-1904/com.example.ebad.testing W/System.err﹕ at com.example.ebad.testing.MainActivity$1.onClick(MainActivity.java:82)
08-06 00:45:10.806 1904-1904/com.example.ebad.testing W/System.err﹕ at android.view.View.performClick(View.java:4756)
08-06 00:45:10.806 1904-1904/com.example.ebad.testing W/System.err﹕ at android.view.View$PerformClick.run(View.java:19749)
08-06 00:45:10.806 1904-1904/com.example.ebad.testing W/System.err﹕ at android.os.Handler.handleCallback(Handler.java:739)
08-06 00:45:10.806 1904-1904/com.example.ebad.testing W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:95)
08-06 00:45:10.806 1904-1904/com.example.ebad.testing W/System.err﹕ at android.os.Looper.loop(Looper.java:135)
08-06 00:45:10.806 1904-1904/com.example.ebad.testing W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:5221)
08-06 00:45:10.806 1904-1904/com.example.ebad.testing W/System.err﹕ at java.lang.reflect.Method.invoke(Native Method)
08-06 00:45:10.806 1904-1904/com.example.ebad.testing W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:372)
08-06 00:45:10.806 1904-1904/com.example.ebad.testing W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
08-06 00:45:10.806 1904-1904/com.example.ebad.testing W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
08-06 00:45:10.807 1904-1904/com.example.ebad.testing W/System.err﹕ Caused by: java.net.ConnectException: socket failed: EACCES (Permission denied)
08-06 00:45:10.807 1904-1904/com.example.ebad.testing W/System.err﹕ at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:181)
08-06 00:45:10.807 1904-1904/com.example.ebad.testing W/System.err﹕ ... 17 more
08-06 00:45:10.807 1904-1904/com.example.ebad.testing W/System.err﹕ Caused by: java.net.SocketException: socket failed: EACCES (Permission denied)
08-06 00:45:10.807 1904-1904/com.example.ebad.testing W/System.err﹕ at libcore.io.IoBridge.socket(IoBridge.java:623)
08-06 00:45:10.807 1904-1904/com.example.ebad.testing W/System.err﹕ at java.net.PlainSocketImpl.create(PlainSocketImpl.java:198)
08-06 00:45:10.807 1904-1904/com.example.ebad.testing W/System.err﹕ at java.net.Socket.checkOpenAndCreate(Socket.java:687)
08-06 00:45:10.807 1904-1904/com.example.ebad.testing W/System.err﹕ at java.net.Socket.connect(Socket.java:847)
08-06 00:45:10.807 1904-1904/com.example.ebad.testing W/System.err﹕ at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119)
08-06 00:45:10.808 1904-1904/com.example.ebad.testing W/System.err﹕ at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:144)
08-06 00:45:10.808 1904-1904/com.example.ebad.testing W/System.err﹕ ... 17 more
08-06 00:45:10.808 1904-1904/com.example.ebad.testing W/System.err﹕ Caused by: android.system.ErrnoException: socket failed: EACCES (Permission denied)
08-06 00:45:10.808 1904-1904/com.example.ebad.testing W/System.err﹕ at libcore.io.Posix.socket(Native Method)
08-06 00:45:10.808 1904-1904/com.example.ebad.testing W/System.err﹕ at libcore.io.BlockGuardOs.socket(BlockGuardOs.java:282)
08-06 00:45:10.808 1904-1904/com.example.ebad.testing W/System.err﹕ at libcore.io.IoBridge.socket(IoBridge.java:608)
08-06 00:45:10.808 1904-1904/com.example.ebad.testing W/System.err﹕ ... 22 more
08-06 00:45:10.808 1904-1904/com.example.ebad.testing D/AndroidRuntime﹕ Shutting down VM
--------- beginning of crash
08-06 00:45:10.809 1904-1904/com.example.ebad.testing E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.ebad.testing, PID: 1904
java.lang.NullPointerException: Attempt to invoke interface method 'org.apache.http.StatusLine org.apache.http.HttpResponse.getStatusLine()' on a null object reference
at com.example.ebad.testing.MainActivity$1.onClick(MainActivity.java:86)
at android.view.View.performClick(View.java:4756)
at android.view.View$PerformClick.run(View.java:19749)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
08-06 00:45:13.333 1904-1904/com.example.ebad.testing I/Process﹕ Sending signal. PID: 1904 SIG: 9
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.ebad.testing" >
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<uses-permission android:name="android.permission.INTERNET" />
</application>
</manifest>
提前致谢。
最佳答案
当您单击“登录”按钮时,您会收到“NetworkOnMainThreadException”。这种异常是由于在 UI 线程上使用网络造成的。
您可以使用异步任务或使用某些库来管理网络通信。我建议你使用 Volley 库。它非常易于使用。
http://www.vogella.com/tutorials/AndroidBackgroundProcessing/article.html https://developer.android.com/training/volley/index.html
关于android - 通过应用程序登录我的大学生门户网站,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31819601/
根据此 Microsoft 指南: https://learn.microsoft.com/en-us/azure/app-service/webjobs-create右键单击 Web 作业时,应该会
我正在尝试在新的 Azure 门户中将网站的开发人员组添加到读者角色,并将用户分配到该组。 当我将特定用户添加到网站的读者角色时,用户可以正常看到所有内容,但是当我删除该用户并将其添加到开发人员组时,
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a software
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a software
我无法验证 Azure Portal在我的家庭桌面(Windows 10 家庭版)上。它只是挂着以下图标,直到我最终被重定向到 error timeout page . 有趣的是,我仍然可以登录 Of
我知道我的问题并不具体,也没有明确的答案,但我需要帮助来弄清楚从哪里开始寻找。 因此,我们在 Azure 门户上工作,并有一个 Web 作业从队列中获取消息并处理它们;由于一些奇怪的原因,当我使用 S
昨天共享我的 Azure 门户仪表板后,我想我不小心删除了我的默认仪表板,因为它与共享仪表板同名。现在,当我登录门户时,我收到以下消息: Dashboard not found We could no
过去几天我收到一个非常奇怪的错误。当我尝试在 Azure 门户中打开任何 SQL Azure 数据库时,我只是在通知中心收到一条错误消息: Refresh the browser to try aga
我在 BizTalk 方面有相当丰富的经验,但对 ESB 工具包还很陌生。我们实际上并不需要这样的 ESB 解决方案,但我想使用 ESB Portal 来显示错误、修改消息并重新提交。 据我所知,我已
昨天共享我的 Azure 门户仪表板后,我想我不小心删除了我的默认仪表板,因为它与共享仪表板同名。现在,当我登录门户时,我收到以下消息: Dashboard not found We could no
过去几天我收到一个非常奇怪的错误。当我尝试在 Azure 门户中打开任何 SQL Azure 数据库时,我只是在通知中心收到一条错误消息: Refresh the browser to try aga
错误 500:java.util.MissingResourceException:找不到 bundle com.ibm.abc.nl.abcdf、 key en_US 的资源。 我收到此异常。我在
我正在尝试编写一个程序,以编程方式将用户登录到 ArcGIS 门户。 这是我的场景: 用户登录到应用程序 A,用户单击指向 ArcGIS 门户的链接 - 我不希望他们在单击该链接时必须登录门户,因为他
React portals让您将 React 子元素渲染到不同的 DOM 元素中,在页面上完全独立的某个位置。 我想做相反的事情:我想在页面的其他地方渲染一次 DOM 元素,然后根据我的 React
我一直在使用 Azure 搜索通过 Azure 门户远程创建的索引 (Umbraco) 中进行搜索。 今天早上,我收到错误消息,告诉我在索引中允许门户来源。 我不明白为什么我昨天能够搜索,而今天它告诉
我曾使用 Websphere Portal 6.0、6.1 并使用 JSR 168、JSR 286 Portlets 开发了门户应用程序。 现在我正在转移到我将使用 Liferay 门户服务器和 JS
如何使用 portal.properties 配置或覆盖 Liferay 门户属性? 最佳答案 Liferay 属性是一种强大的工具,它允许我们配置 Portal 行为而无需编写 hooks-、ext
我已经安装了 FIM Portal 并且安装成功。但是,我无法在 FI 上查看导航栏和管理控件 最佳答案 在集合 --> 搜索管理员 --> 将您的用户 ID 添加到该集合。 关于sharepoint
我的 Web 应用程序部署在 Azure 门户中。我想从我的解决方案中删除整个 web.config 文件,并想在 Azure 中配置它。是否可以做到这一点,如果可能的话,我需要在哪里提供azure中
我认为这是不可能的,但我想知道是否有任何网址可以将我重定向到标准逻辑应用程序(单租户)中的特定工作流程。 我为什么要问这个问题,因为在消费逻辑应用程序中,如果我向某人提供 URL,他们会直接进入概述页
我是一名优秀的程序员,十分优秀!