Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/179.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java org.ksoap2.serialization.SoapSerializationEnvelope_Java_Android_Soap_Ksoap - Fatal编程技术网

Java org.ksoap2.serialization.SoapSerializationEnvelope

Java org.ksoap2.serialization.SoapSerializationEnvelope,java,android,soap,ksoap,Java,Android,Soap,Ksoap,有人能帮我清除这个错误吗 我已经做了所有的设置。。。还选择了java构建路径中的jar文件。。我的文件夹也仅以libs的名义。。。当我使用登录按钮将我的Web服务与我的android应用程序连接时,错误总是显示出来 我的应用程序包含证书过期网页的证书问题。。我添加了代码以绕过证书错误 但当我单击“登录”按钮时,总会发生此SoapSerialization错误 这是我的密码 package com.test.mqilynx; import javax.net.ssl.HttpsURLC

有人能帮我清除这个错误吗

我已经做了所有的设置。。。还选择了java构建路径中的jar文件。。我的文件夹也仅以libs的名义。。。当我使用登录按钮将我的Web服务与我的android应用程序连接时,错误总是显示出来

我的应用程序包含证书过期网页的证书问题。。我添加了代码以绕过证书错误

但当我单击“登录”按钮时,总会发生此SoapSerialization错误

这是我的密码

    package com.test.mqilynx;


import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import android.app.Activity;
import android.os.Bundle;
import android.os.StrictMode;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (android.os.Build.VERSION.SDK_INT > 9) {
 StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
   StrictMode.setThreadPolicy(policy);
}
Button loginb = (Button) findViewById(R.id.button1);
loginb.setOnClickListener( new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
EditText uname = (EditText) findViewById(R.id.editText1);
EditText pwd = (EditText) findViewById(R.id.editText2);
String ustr = uname.getText().toString();
        String pstr = pwd.getText().toString();
        if (ustr.isEmpty() && pstr.isEmpty()){
            Toast to = Toast.makeText(MainActivity.this,"Please Login credentials",Toast.LENGTH_SHORT);
            to.setGravity(Gravity.CENTER, 0, 0);
            to.show();
        }
        else
        { if (ustr.isEmpty() || pstr.isEmpty())
            {
             if(ustr.isEmpty()){
             Toast to = Toast.makeText(MainActivity.this,"Please Enter Username",Toast.LENGTH_SHORT);
            to.setGravity(Gravity.CENTER, 0, 0);
            to.show();}
            else{
                Toast to = Toast.makeText(MainActivity.this,"Please Enter Password",Toast.LENGTH_SHORT);
                to.setGravity(Gravity.CENTER, 0, 0);
                to.show();
            }
                }
             else 
             {
                // Toast.makeText(getBaseContext(),"Welcome! " + ustr + " Pwd: "+ pstr,Toast.LENGTH_SHORT).show();


                 String METHOD_NAME = "Login";
                 String NAMESPACE = "https://www.qilynx.com/loadsoap.php";
                 String SOAP_ACTION = "https://www.qilynx.com/loadsoap.php/Login";
                // String URL = "https://auth:1qaz2wsx3edc4rfv@www.qilynx.com/loadsoap.php?desc";
                 String URL = "https://www.qilynx.com:443/loadsoap.php";
                 SoapObject userReq = new SoapObject(NAMESPACE,METHOD_NAME);
                 userReq.addProperty("user",ustr);
                 userReq.addProperty("pass",pstr);
                 System.out.println("user: " + "" + ustr + ":" + "Pwd: " + pstr);

            //   SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
            //   request.addProperty("Login", userReq);

                 SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
                // envelope.bodyOut = request;
                 envelope.dotNet=true;
                 envelope.setOutputSoapObject(userReq);
                 Log.e("Value of Req", userReq.toString());
                 Log.e("Value of Envelope", envelope.toString());
                // Log.i("bodyenv", envelope.bodyOut.toString());

                 HttpTransportSE androidHTTPTransport = new HttpTransportSE(URL);

                 //By-passing certificate - START
                // Create a trust manager that does not validate certificate chains



                 TrustManager[] trustAllCerts = new TrustManager[]{
                     new X509TrustManager() {
                         public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                             return null;
                         }
                         public void checkClientTrusted(
                             java.security.cert.X509Certificate[] certs, String authType) {
                         }
                         public void checkServerTrusted(
                             java.security.cert.X509Certificate[] certs, String authType)  {
                         }
                     }
                 };

                 // Install the all-trusting trust manager
                 try {
                     SSLContext sc = SSLContext.getInstance("SSL");
                     sc.init(null, trustAllCerts, new java.security.SecureRandom());
                     HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
                 } catch (Exception e) {
                     e.printStackTrace();
                 }


                 // By-passing certificate - END
                 try{
                     System.out.println("I AM IN TRY");
                     System.out.println("envelope1 "+envelope);
                     androidHTTPTransport.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
                     System.out.println("Before Bp1");
                     System.out.println("Bp 1");
                     androidHTTPTransport.call(SOAP_ACTION,envelope);
                     System.out.println("after Bp1");
                     System.out.println("Bp 2");
                     SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
                        Log.v("TAG",String.valueOf(resultsRequestSOAP));

                     System.out.println("envelope2 "+envelope); 
                     System.out.println("before resp");
                     SoapObject resp = (SoapObject) envelope.getResponse();
                     Log.i("return", resp.toString());
                     boolean check = Boolean.parseBoolean(resp.getProperty("result").toString());
                     if(check)
                     {
                         System.out.println("SUCCESS LOGIN");
                         /*Toast to = Toast.makeText(MainActivity.this,"Logged In",Toast.LENGTH_SHORT);
                            to.setGravity(Gravity.CENTER, 0, 0);
                            to.show(); */
                     }

                     else
                     {
                         /*Toast to = Toast.makeText(MainActivity.this,"Failed",Toast.LENGTH_SHORT);
                            to.setGravity(Gravity.CENTER, 0, 0);
                            to.show();*/
                         System.out.println("LOGIN FAILED");
                     }

                 }

                 catch(Exception e)
                 {
                     System.out.println("I AM IN ERROR");
                    e.printStackTrace(); 
                 }
             }
        }
        }
    });

}

转到Project/Properties/Java Build Path/Order and Export——确保在Android依赖项和支持库前面有一个复选框(如果您使用它)。标记所有复选框,然后单击Apply并清除项目

((Button)findViewById(R.id.btnData)).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            NAMESPACE = "http://tempuri.org/";
            URL = "http://YOURURL/Service.asmx";
            SOAP_ACTION = "http://tempuri.org/SetLoginData";
            METHOD_NAME = "SetLoginData";
            EditText uname = (EditText) findViewById(R.id.editText1);
            EditText pwd = (EditText) findViewById(R.id.editText2);       

            String dataToSend="[{'UserID':uname.getText().toString() ,'Password':pwd.getText().toString() }]";

            SendData(dataToSend);
        }
    });
}

public void SendData(String data){

    Log.d(TAG, "SendData");
    Log.d(TAG, "URL   : "+URL);
    Log.d(TAG, "ACTION: "+SOAP_ACTION);

    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);

    Log.d(TAG, "Create");
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
    String dataToSend=data;
    Log.d(TAG, "dataToSend: "+dataToSend);

    PropertyInfo FromCurrency = new PropertyInfo();
    FromCurrency.setName("strInputData");
    FromCurrency.setValue(dataToSend);
    FromCurrency.setType(String.class);
    request.addProperty(FromCurrency);

    Log.d(TAG, "envelope");
    // Create the envelop.Envelop will be used to send the request
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

    envelope.implicitTypes=true;
    envelope.setAddAdornments(false);

    envelope.setOutputSoapObject(request);
    // Says that the soap webservice is a .Net service
    envelope.dotNet = true;

    Log.d(TAG, "URL");
    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

    try {
        Log.d(TAG, "call");
        androidHttpTransport.call(SOAP_ACTION, envelope);
        Log.d(TAG, "call1");
        SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
        Log.d(TAG,"response:"+ response.toString());
        TextView v = (TextView) findViewById(R.id.currency);
        v.setText("Retururn Responce" +  "= " + response.toString() ); 
    } catch (Exception e){
        e.printStackTrace();
    }
}

这个Web服务将获取json数据,这就是我用json传递数据的原因。所以您必须检查名称空间是什么,xml或json数据,FromCurrency.setName(“strInputData”);哪个是#c开发者函数参数名称和所需的internet权限。

如何清理项目?在eclipse中,转到状态栏中的“项目”,然后单击“清理”,然后单击“确定”。完成后。。但还是发生了同样的事情。。。我正在使用ksoap2-j2se-full-2.1.2.jar进行我的项目…还需要什么信息来解决我的问题?请告诉我..张贴你的日志和名称空间,函数名称和代码使用你是calling@Pankaj请查看我的代码我认为你的代码是正确的,但我必须在浏览器上测试,因为.net方面缺少一些东西,直到我使用了我从未使用过的名称空间,就像你使用过的那样,我使用过tempuri.org,但我无法从浏览器方面进行测试。。由于我的网站,我正在寻找是得到证书过期。。因此,我通过一个代码绕过tat,在android应用程序中访问。。因此,SOAP功能在运行应用程序并点击登录按钮时进行猜测。。。
((Button)findViewById(R.id.btnData)).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            NAMESPACE = "http://tempuri.org/";
            URL = "http://YOURURL/Service.asmx";
            SOAP_ACTION = "http://tempuri.org/SetLoginData";
            METHOD_NAME = "SetLoginData";
            EditText uname = (EditText) findViewById(R.id.editText1);
            EditText pwd = (EditText) findViewById(R.id.editText2);       

            String dataToSend="[{'UserID':uname.getText().toString() ,'Password':pwd.getText().toString() }]";

            SendData(dataToSend);
        }
    });
}

public void SendData(String data){

    Log.d(TAG, "SendData");
    Log.d(TAG, "URL   : "+URL);
    Log.d(TAG, "ACTION: "+SOAP_ACTION);

    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);

    Log.d(TAG, "Create");
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
    String dataToSend=data;
    Log.d(TAG, "dataToSend: "+dataToSend);

    PropertyInfo FromCurrency = new PropertyInfo();
    FromCurrency.setName("strInputData");
    FromCurrency.setValue(dataToSend);
    FromCurrency.setType(String.class);
    request.addProperty(FromCurrency);

    Log.d(TAG, "envelope");
    // Create the envelop.Envelop will be used to send the request
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

    envelope.implicitTypes=true;
    envelope.setAddAdornments(false);

    envelope.setOutputSoapObject(request);
    // Says that the soap webservice is a .Net service
    envelope.dotNet = true;

    Log.d(TAG, "URL");
    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

    try {
        Log.d(TAG, "call");
        androidHttpTransport.call(SOAP_ACTION, envelope);
        Log.d(TAG, "call1");
        SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
        Log.d(TAG,"response:"+ response.toString());
        TextView v = (TextView) findViewById(R.id.currency);
        v.setText("Retururn Responce" +  "= " + response.toString() ); 
    } catch (Exception e){
        e.printStackTrace();
    }
}