当我将我的http网址更改为https ..
时,我遇到了问题例如我的第一个网址是和应用程序正常工作:
http://hello.com/app/service.asmx
当我用https更改网址时,它就崩溃了
https://hello.com/app/service.asmx
任何解决方案?事先感谢Alot
这是我的MainActivity:
public class MainActivity extends ActionBarActivity {
Button btn_signin;
EditText et_username;
EditText et_password;
Button btn_login;
Button btn_create_login;
String username;
String password;
JSONParser jsonParser = new JSONParser();
ProgressDialog pDialog;
ProgressDialog prgDialog;
TextView errorMsg;
TextView tv_forgotpass;
TextView tv_login_num;
AlertDialog alert;
private final String NAMESPACE = "http://tempuri.org/";
private final String URL = urls.base_url;
private final String SOAP_ACTION = "http://tempuri.org/Login";
private final String METHOD_NAME = "Login";
// SoapPrimitive response;
HttpTransportSE androidHttpTransport;
SoapSerializationEnvelope envelope;
SoapObject request;
String message;// = c.getString("message");
int sessionid;// = c.getInt("sessionid");
int saleid;// = c.getInt("saleid");
String name;// = c.getString("name");
String email;// = c.getString("email");
String defaultmsisdn;// = c.getString("defaultmsisdn");
String associatedmsisdn;
int associatedsaleid;
String associatedmsisdn1;
int associatedsaleid1;
// final List<String> AssociatedArray = new ArrayList<String>();
private ArrayList<String> AssociatedArray = new ArrayList<String>();
String associatedArray = null;
List myArray = new ArrayList<String>();
SharedPreferences progress;
SharedPreferences.Editor progress_editor;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
progress = getSharedPreferences("SelfCarePref", MODE_PRIVATE);
progress_editor = progress.edit();
progress_editor.clear();
progress_editor.commit();
ActionBar actionBar = getSupportActionBar();
actionBar.setLogo(R.drawable.ic_launcher);
actionBar.setDisplayUseLogoEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);
}
et_username = (EditText) findViewById(R.id.editText_Mobile);
et_password = (EditText) this.findViewById(R.id.editText_password);
btn_signin = (Button) findViewById(R.id.btn_signin);
btn_create_login = (Button) findViewById(R.id.btn_create_login);
tv_forgotpass = (TextView) findViewById(R.id.tv_forgotpass);
tv_login_num = (TextView) findViewById(R.id.tv_login_num);
prgDialog = new ProgressDialog(this);
// Set Progress Dialog Text
prgDialog.setMessage("Please wait...");
// Set Cancelable as False
prgDialog.setCancelable(false);
pDialog = new ProgressDialog(MainActivity.this);
btn_create_login.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(MainActivity.this,
RegisterActivity.class);
startActivity(intent);
et_username.setText("");
et_password.setText("");
}
});
btn_signin.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
loginAction();
}
});
tv_login_num.setText(Html.fromHtml("<u>Login with Number</u>"));
tv_login_num.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(MainActivity.this, LoginNumber.class);
startActivity(intent);
et_username.setText("");
et_password.setText("");
}
});
tv_forgotpass.setText(Html.fromHtml("<u>Forgot Credentials</u>"));
tv_forgotpass.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(MainActivity.this, Forgot.class);
startActivity(intent);
et_username.setText("");
et_password.setText("");
// finish();
}
});
//Check if contact is already exists or not in Contact list
/*if(contactExists(this,"0344"))
{
Toast.makeText(MainActivity.this,"baba exists",Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(MainActivity.this," not exists",Toast.LENGTH_SHORT).show();
}*/
}
public boolean contactExists(Activity _activity,String number){
Uri lookupUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI,Uri.encode(number));
String[] mPhoneNumberProjection = { PhoneLookup._ID, PhoneLookup.NUMBER, PhoneLookup.DISPLAY_NAME };
Cursor cur = _activity.getContentResolver().query(lookupUri,mPhoneNumberProjection, null, null, null);
try {
if (cur.moveToFirst()) {
// if contact are in contact list it will return true
return true;
}} finally {
if (cur != null)
cur.close();
}
//if contact are not match that means contact are not added
return false;
}
private void loginAction() {
request = new SoapObject(NAMESPACE, METHOD_NAME);
Log.d("SelfCare", "NAMESPACE= " + NAMESPACE);
Log.d("SelfCare", "METHOD_NAME= " + METHOD_NAME);
// EditText userName = (EditText) findViewById(R.id.editText1);
username = et_username.getText().toString();
// EditText userPassword = (EditText) findViewById(R.id.editText2);
String user_Password = et_password.getText().toString();
String apptypecode = "TXDIY0006";
Log.d("SelfCare", "user_Name= " + username);
Log.d("SelfCare", "password= " + user_Password);
/*
* request.addProperty("username", user_Name);
* request.addProperty("password", user_Password);
* request.addProperty("apptypecode", apptypecode);
*/
// Pass value for userName variable of the web service
if (username.trim().equals("")) {
alertDialog("Please Enter Username");
et_username.requestFocus();
} else if (user_Password.equals("")) {
alertDialog("Please Enter Your Password");
et_password.requestFocus();
} else {
progress_editor = progress.edit();
progress_editor.putString("username", username);
progress_editor.putString("password", user_Password);
progress_editor.commit();
PropertyInfo unameProp = new PropertyInfo();
unameProp.setName("username");// Define the variable name in the web
// service method
unameProp.setValue(username);// set value for userName variable
unameProp.setType(String.class);// Define the type of the variable
request.addProperty(unameProp);// Pass properties to the variable
// Pass value for Password variable of the web service
PropertyInfo passwordProp = new PropertyInfo();
passwordProp.setName("password");
passwordProp.setValue(user_Password);
passwordProp.setType(String.class);
request.addProperty(passwordProp);
PropertyInfo apptypecodes = new PropertyInfo();
apptypecodes.setName("apptypecode");
apptypecodes.setValue(apptypecode);
apptypecodes.setType(String.class);
request.addProperty(apptypecodes);
new AsyncCallWS().execute();
}
}
/*@Override
protected void onDestroy() {
// TODO Auto-generated method stub
progress_editor = progress.edit();
progress_editor.clear();
progress_editor.commit();
super.onDestroy();
}*/
private class AsyncCallWS extends AsyncTask<String, Void, Void> {
@Override
protected Void doInBackground(String... params) {
try {
envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
envelope.dotNet = true;
Log.d("SelfCare", "request= " + request);
// androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport = new HttpTransportSE(URL, 60000);
Log.d("SelfCare", "androidHttpTransport= "
+ androidHttpTransport);
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
Log.d("SelfCare", "response= " + response);
/*
* Toast.makeText(getApplicationContext(), "Response= " +
* response, Toast.LENGTH_LONG).show();
*/
String jsonResponse = "";
jsonResponse = response.toString();
// A JSONTokener is needed in order to use JSONObject correctly
JSONTokener jsonTokener = new JSONTokener(jsonResponse);
// Pass a JSONTokener to the JSONObject constructor
JSONObject jsonObj = new JSONObject(jsonTokener);
JSONArray data = jsonObj.getJSONArray("data");
if (data != null) {
// looping through All nodes
for (int i = 0; i < data.length(); i++) {
JSONObject c = data.getJSONObject(i);
message = c.getString("message");
sessionid = c.getInt("sessionid");
saleid = c.getInt("saleid");
name = c.getString("name");
email = c.getString("email");
defaultmsisdn = c.getString("defaultmsisdn");
associatedArray = c.getString("AssociatedArray");
AssociatedArray.add(associatedArray);
Log.d("SelfCare farhan aarray", "AssociatedArray= "
+ AssociatedArray);
// Log.d("SelfCare farhan aarray", "AssociatedArray= " +
// myArray);
/*
* associatedmsisdn = c.getString("associatedmsisdn");
* associatedsaleid = c.getInt("associatedsaleid");
* associatedmsisdn1 = c.getString("associatedmsisdn1");
* associatedsaleid1 = c.getInt("associatedsaleid1");
*
* Log.d("SelfCare", "message= " + message);
* Log.d("SelfCare", "sessionid= " + sessionid);
* Log.d("SelfCare", "associatedmsisdn= " +
* associatedmsisdn); Log.d("SelfCare",
* "associatedsaleid= " + associatedsaleid);
* Log.d("SelfCare", "associatedmsisdn1= " +
* associatedmsisdn1); Log.d("SelfCare",
* "associatedsaleid1= " + associatedsaleid1);
*/
}
/*
* Toast.makeText(getBaseContext(), "Success",
* Toast.LENGTH_LONG).show();
*/
} else {
/*
* Toast.makeText(getBaseContext(), "Error",
* Toast.LENGTH_LONG) .show();
*/}
/*
* TextView results = (TextView) findViewById(R.id.login_error);
* results.setText(response.toString());
*/
} catch (Exception e) {
// alertDialog(e.toString());
/*
* Toast.makeText(getApplicationContext(), e.getMessage(),
* Toast.LENGTH_LONG).show();
*/
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
// Log.i(TAG, "onPostExecute");
// tv.setText(fahren + "° F");
pDialog.dismiss();
if (message != null) {
//Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
if (message.equalsIgnoreCase("Login Successful.")) {
if (defaultmsisdn.equalsIgnoreCase("null") && saleid == 0) {
et_username.setText("");
et_password.setText("");
Intent intent = new Intent(getApplicationContext(),
AssociateMsisdn.class);
intent.putExtra("username", username);
intent.putExtra("sessionid", sessionid);
intent.putExtra("name", name);
intent.putExtra("email", email);
intent.putExtra("AssociatedArray", associatedArray);
startActivity(intent);
// alertDialog("Open the Associate MSISDN Class.");
} else {
et_username.setText("");
et_password.setText("");
Intent intent = new Intent(getApplicationContext(),
MainMenu.class);
intent.putExtra("name", name);
intent.putExtra("username", username);
intent.putExtra("defaultmsisdn", defaultmsisdn);
intent.putExtra("sessionid", sessionid);
intent.putExtra("saleid", saleid);
intent.putExtra("email", email);
intent.putExtra("AssociatedArray", associatedArray);
Log.d("SelfCare farhan aarray put", "AssociatedArray= "
+ AssociatedArray);
// intent.putStringArrayListExtra("AssociatedArray",
// AssociatedArray);
/*
* intent.putExtra("associatedmsisdn",
* associatedmsisdn);
* intent.putExtra("associatedsaleid",
* associatedsaleid);
* intent.putExtra("associatedmsisdn1",
* associatedmsisdn1);
* intent.putExtra("associatedsaleid1",
* associatedsaleid1);
*/
startActivity(intent);
}
} else {
alertDialog(message);
// Toast.makeText(getApplicationContext(), "" +message ,
// Toast.LENGTH_LONG).show();
}
} else {
alertDialog(getResources().getString(R.string.server_error));
}
}
@Override
protected void onPreExecute() {
pDialog.setMessage("Logging in ...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
@Override
protected void onProgressUpdate(Void... values) {
// Log.i(TAG, "onProgressUpdate");
}
}
public void alertDialog(String Error) {
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setMessage(Error).setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// do things
alert.cancel();
}
});
alert = builder.create();
alert.show();
}
public void alertDialogSuccess(String Error) {
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setMessage(Error).setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// do things
/*
* Intent intent = new Intent( getApplicationContext(),
* ActivateUser.class); intent.putExtra("username",
* username); startActivity(intent);
*/
}
});
alert = builder.create();
alert.show();
}
public void alert() {
AlertDialog.Builder builder1 = new AlertDialog.Builder(
MainActivity.this);
// set title
builder1.setTitle("Email Verification via SMS");
builder1.setMessage("farhan shah");
builder1.setCancelable(true);
builder1.setPositiveButton("Yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
builder1.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert11 = builder1.create();
alert11.show();
}
public void navigatetoHomeActivity() {
Intent homeIntent = new Intent(getApplicationContext(), MainMenu.class);
homeIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(homeIntent);
}
}