commit
e70f664872
Binary file not shown.
@ -0,0 +1,27 @@
|
||||
package com.example.PersonalCenter;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
public class Login {
|
||||
|
||||
private String password;
|
||||
private String phonenumber;
|
||||
public Login(String phonenumber,String password){
|
||||
|
||||
this.password = password;
|
||||
this.phonenumber = phonenumber;
|
||||
|
||||
}
|
||||
public String connUser(){
|
||||
String infoString = WebServiceGet.executeHttpGet(phonenumber,password,"/Login");
|
||||
// if(infoString.equals("false")){
|
||||
// Log.i("Login","+++++++++++fail"+infoString);
|
||||
// }else {
|
||||
// Log.i("Login","+++++++++++successs"+infoString);
|
||||
// }
|
||||
//登录成功后返回用户名
|
||||
while(infoString==null){}
|
||||
Log.i("sucesss",infoString+"ha");
|
||||
return infoString;
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package com.example.PersonalCenter;
|
||||
|
||||
public class Register {
|
||||
String phonenumber;
|
||||
String username;
|
||||
String password;
|
||||
public Register(String phonenumber, String username, String password){
|
||||
this.phonenumber = phonenumber;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
}
|
||||
public boolean regist(){
|
||||
String regRet = WebServicePost.execuHttpPost(username, phonenumber, password,"/Register");
|
||||
if(regRet.equals("true")){
|
||||
return true;
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
package com.example.PersonalCenter;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
public class WebServiceGet {
|
||||
public static String executeHttpGet(String phonenumber,String password,String address){
|
||||
HttpURLConnection connection = null;
|
||||
InputStream in = null;
|
||||
|
||||
String Url = "http://106.54.210.208:8080/ChineseM"+address;
|
||||
String path = Url+"?phonenumber=" + phonenumber + "&password=" + password;
|
||||
URL url = null;
|
||||
try {
|
||||
url = new URL(path);
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
connection = (HttpURLConnection)url.openConnection();
|
||||
connection.setRequestMethod("GET");
|
||||
connection.setConnectTimeout(100000);//建立连接超时
|
||||
connection.setReadTimeout(80000);//传输数据超时
|
||||
in = connection.getInputStream();
|
||||
return parseInfo(in);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
if(connection != null){
|
||||
connection.disconnect();
|
||||
}
|
||||
if(in != null){
|
||||
try {
|
||||
in.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
//将字节流转换成String
|
||||
public static String parseInfo(InputStream inputStream){
|
||||
BufferedReader reader = null;
|
||||
String line = "";
|
||||
StringBuilder response = new StringBuilder();
|
||||
try {
|
||||
reader = new BufferedReader(new InputStreamReader(inputStream));
|
||||
while((line = reader.readLine()) != null) {
|
||||
response.append(line);
|
||||
}
|
||||
return response.toString();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
if(reader!=null){
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,91 @@
|
||||
package com.example.PersonalCenter;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
public class WebServicePost {
|
||||
public static String execuHttpPost(String username,String phonenumber,String password,String address){
|
||||
HttpURLConnection connection = null;
|
||||
InputStream in = null;
|
||||
String path = "http://106.54.210.208:8080/ChineseM/"+address;
|
||||
URL url = null;
|
||||
try {
|
||||
url = new URL(path);
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
connection = (HttpURLConnection) url.openConnection();
|
||||
connection.setDoInput(true);
|
||||
connection.setDoOutput(true);
|
||||
connection.setRequestMethod("POST");
|
||||
connection.setReadTimeout(8000);
|
||||
connection.setUseCaches(false);
|
||||
connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
|
||||
connection.connect();
|
||||
DataOutputStream out = new DataOutputStream(connection.getOutputStream());
|
||||
String data = "username="+ URLEncoder.encode(username,"UTF-8")+"&phonenumber="+URLEncoder.encode(phonenumber,"UTF-8")+"&password="+URLEncoder.encode(password,"UTF-8");
|
||||
out.writeBytes(data);
|
||||
out.flush();
|
||||
out.close();
|
||||
int resultCode = connection.getResponseCode();
|
||||
if(HttpURLConnection.HTTP_OK == resultCode){
|
||||
in = connection.getInputStream();
|
||||
return parseInfo(in);
|
||||
}
|
||||
return null;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
if(connection != null){
|
||||
connection.disconnect();
|
||||
}
|
||||
if(in != null){
|
||||
try {
|
||||
in.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
public static String parseInfo(InputStream inputStream){
|
||||
BufferedReader reader = null;
|
||||
String line = "";
|
||||
StringBuilder response = new StringBuilder();
|
||||
reader = new BufferedReader(new InputStreamReader(inputStream));
|
||||
|
||||
try {
|
||||
while((line = reader.readLine())!=null){
|
||||
Log.d("RegisterActivity",line);
|
||||
response.append(line);
|
||||
}
|
||||
Log.d("RegisterActivity","response.toSring:"+response.toString());
|
||||
return response.toString();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
if(reader != null){
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
<network-security-config>
|
||||
<domain-config>
|
||||
<domain includeSubdomains="true">example.com</domain>
|
||||
<pin-set expiration="2018-01-01">
|
||||
<pin digest="SHA-256">7HIpactkIAq2Y49orFOOQKurWxmmSFZhBCoQYcRhJ3Y=</pin>
|
||||
<!-- backup pin -->
|
||||
<pin digest="SHA-256">fwza0LRMXouZHRC8Ei+4PyuldPDcf3UKgO/04cDM1oE=</pin>
|
||||
</pin-set>
|
||||
</domain-config>
|
||||
</network-security-config>
|
Loading…
Reference in new issue