使用 HTTP POST 数据正常,当我使用 SOAP 发送数据时它会 empty/null
With HTTP POST the data goes fine, when I send data with SOAP it goes empty/null
使用 HTTP POST 数据正常,当我使用 SOAP 发送数据时它 empty/null。我通过在服务器上保留日志来检测到这一点。因为我在java这边发送的变量好像已经满了
public class YLogin extends AppCompatActivity {
EditText yoneticieposta, yoneticiparola;
Button yoneticiDGiris;
String Eposta, Parola, ReturnResult;
/*Web Service*/
public static String URL="https://api.example.com/MCG-WS.asmx?WSDL";
public static String NAMESPACE="http://tempuri.org";
/*Login API*/
public static String SOAP_ACTION_LOGIN="http://tempuri.org/LoginAPI";
public static String METHOD_NAME_LOGIN="LoginAPI";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ylogin);
yoneticieposta = (EditText) findViewById(R.id.yoneticiepostaTx);
yoneticiparola = (EditText) findViewById(R.id.yoneticiparolaTx);
yoneticiDGiris = (Button) findViewById(R.id.yoneticiDGirisYapBt);
yoneticiDGiris.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Eposta = yoneticieposta.getText().toString();
Parola = yoneticiparola.getText().toString();
if(Eposta.isEmpty() || Parola.isEmpty()){
Toast.makeText(YLogin.this, "E-posta veya parola kısımlarını doldurun.", Toast.LENGTH_SHORT).show();
}else{
new LoginAsyncTask().execute(Eposta, Parola);
}
}
});
}
private class LoginAsyncTask extends AsyncTask<String, Void, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected String doInBackground(String... strings){
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME_LOGIN);
PropertyInfo infoEposta = new PropertyInfo();
infoEposta.setName("eposta");
infoEposta.setType(String.class);
infoEposta.setValue(strings[0].toString());
request.addProperty(infoEposta);
PropertyInfo infoParola = new PropertyInfo();
infoParola.setName("parola");
infoParola.setType(String.class);
infoParola.setValue(strings[1].toString());
request.addProperty(infoParola);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet =true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.call(SOAP_ACTION_LOGIN, envelope);
if (envelope.bodyIn instanceof SoapFault) {
SoapFault error = (SoapFault) envelope.bodyIn;
System.out.println("TTTTTTTTTTTTTT Error message : " + error.toString());
}
if (envelope.bodyIn instanceof SoapObject) {
SoapObject result = (SoapObject) envelope.bodyIn;
if(result!=null){
ReturnResult = result.getProperty(0).toString();
}
}
}
catch(Exception e){
e.printStackTrace();
return e.toString();
}
return ReturnResult;
}
@Override
protected void onPostExecute(String result) {
if(result.equals("başarılı")){
Intent intent = new Intent(YLogin.this, dashboard.class);
intent.putExtra("yoneticiEposta", Eposta);
startActivity(intent);
}else{
Toast.makeText(YLogin.this, "E-posta veya parolanız yanlış, tekrar deneyin.", Toast.LENGTH_SHORT).show();
}
}
}
}
request.addProperty("eposta", Eposta);
request.addProperty("parola", Parola);
即使我尝试了,问题仍然存在。
数据丢失的原因可能是什么 empty/null?你能帮忙吗?
我忘了在命名空间的末尾添加“/”符号。
是的,这是唯一的问题和解决方案:)
使用 HTTP POST 数据正常,当我使用 SOAP 发送数据时它 empty/null。我通过在服务器上保留日志来检测到这一点。因为我在java这边发送的变量好像已经满了
public class YLogin extends AppCompatActivity {
EditText yoneticieposta, yoneticiparola;
Button yoneticiDGiris;
String Eposta, Parola, ReturnResult;
/*Web Service*/
public static String URL="https://api.example.com/MCG-WS.asmx?WSDL";
public static String NAMESPACE="http://tempuri.org";
/*Login API*/
public static String SOAP_ACTION_LOGIN="http://tempuri.org/LoginAPI";
public static String METHOD_NAME_LOGIN="LoginAPI";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ylogin);
yoneticieposta = (EditText) findViewById(R.id.yoneticiepostaTx);
yoneticiparola = (EditText) findViewById(R.id.yoneticiparolaTx);
yoneticiDGiris = (Button) findViewById(R.id.yoneticiDGirisYapBt);
yoneticiDGiris.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Eposta = yoneticieposta.getText().toString();
Parola = yoneticiparola.getText().toString();
if(Eposta.isEmpty() || Parola.isEmpty()){
Toast.makeText(YLogin.this, "E-posta veya parola kısımlarını doldurun.", Toast.LENGTH_SHORT).show();
}else{
new LoginAsyncTask().execute(Eposta, Parola);
}
}
});
}
private class LoginAsyncTask extends AsyncTask<String, Void, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected String doInBackground(String... strings){
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME_LOGIN);
PropertyInfo infoEposta = new PropertyInfo();
infoEposta.setName("eposta");
infoEposta.setType(String.class);
infoEposta.setValue(strings[0].toString());
request.addProperty(infoEposta);
PropertyInfo infoParola = new PropertyInfo();
infoParola.setName("parola");
infoParola.setType(String.class);
infoParola.setValue(strings[1].toString());
request.addProperty(infoParola);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet =true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.call(SOAP_ACTION_LOGIN, envelope);
if (envelope.bodyIn instanceof SoapFault) {
SoapFault error = (SoapFault) envelope.bodyIn;
System.out.println("TTTTTTTTTTTTTT Error message : " + error.toString());
}
if (envelope.bodyIn instanceof SoapObject) {
SoapObject result = (SoapObject) envelope.bodyIn;
if(result!=null){
ReturnResult = result.getProperty(0).toString();
}
}
}
catch(Exception e){
e.printStackTrace();
return e.toString();
}
return ReturnResult;
}
@Override
protected void onPostExecute(String result) {
if(result.equals("başarılı")){
Intent intent = new Intent(YLogin.this, dashboard.class);
intent.putExtra("yoneticiEposta", Eposta);
startActivity(intent);
}else{
Toast.makeText(YLogin.this, "E-posta veya parolanız yanlış, tekrar deneyin.", Toast.LENGTH_SHORT).show();
}
}
}
}
request.addProperty("eposta", Eposta);
request.addProperty("parola", Parola);
即使我尝试了,问题仍然存在。
数据丢失的原因可能是什么 empty/null?你能帮忙吗?
我忘了在命名空间的末尾添加“/”符号。
是的,这是唯一的问题和解决方案:)