有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java简单的安卓和ASP。净组合

我编写了一个安卓应用程序,将文本数据发送到asp。net网络服务器。我正在使用下一个代码通过Http发送数据:

try {
    URL url = new URL(serverUrl);
    connection = (HttpURLConnection)url.openConnection();
    connection.setDoInput(true);
    connection.setDoOutput(true);
    connection.setUseCaches(false);

    // Enable POST method
    connection.setRequestMethod("POST");

    connection.setRequestProperty("Connection", "Keep-Alive");
    connection.setRequestProperty("Content-Type", "text/plain; charset=utf-8");
    output = new DataOutputStream(connection.getOutputStream());
    String finalUri = sendedUrl.replace("gaburl", "");
    output.writeChars(finalUri);
    //Toast.makeText(context, finalUri, 1000).show();
    output.flush();
    output.close();
}
catch(Exception e) {
    Toast.makeText(context, e.toString(), 5);
}

如何在ASP中接收和显示通过output.writeChars(finalUri)方法发送的数据。网络应用这个过程应该像下面描述的那样执行:

1)我们有asp。net表单是发送者的安卓方法的目标,这些表单在更早的时候就不成熟了

2)表单应该读取发送给它的字符串数据并显示

请帮帮我


共 (1) 个答案

  1. # 1 楼答案

    Using Ksoap2 library and write .net web service 
    Sucessful Connection with Asp.net Webservice  -
    package ProductVerificationCard.in;
    
    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.content.Intent;
    import android.os.Bundle;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.TextView;
    
    public class AdminLogin extends Activity {
        /** Called when the activity is first created. */
        Button btn_ok;
        TextView textView;
        private static final String SOAP_ACTION = "http://tempuri.org/Login";
    
        private static final String OPERATION_NAME = "Login";
    
        private static final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/";
    
        private static final String SOAP_ADDRESS = "http://10.0.2.2/new/WebService.asmx";
        String s;
    
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            btn_ok=(Button) findViewById(R.id.btn_login);
            textView=(TextView) findViewById(R.id.tv_error);
    
            btn_ok.setOnClickListener(new OnClickListener() {
    
                public void onClick(View v) {
                    SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,
                            OPERATION_NAME);
    
                            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                            SoapEnvelope.VER11);
                            envelope.dotNet = true;
    
                            envelope.setOutputSoapObject(request);
    
                            HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
    
                            try
    
                            {
    
                            httpTransport.call(SOAP_ACTION, envelope);
    
                            Object response = envelope.getResponse();
    
                            //textView.setText(response.toString());
                             s=response.toString();
                             if(s=="true")
                             {
                                 Intent intent=new Intent(AdminLogin.this,MenuForm.class);
                                    startActivity(intent);
    
                             }
    
                             else
                             {
                                 textView.setText("Enter Valid Username or Password");
                             }
                            }
    
                            catch (Exception exception)
    
                            {
    
                            textView.setText(exception.toString());
    
                            }
                    // TODO Auto-generated method stub
                    }
            });
    
        }
    }