gpt4 book ai didi

java - 简单的 android 和 ASP.NET 组合

转载 作者:行者123 更新时间:2023-12-02 07:32:57 25 4
gpt4 key购买 nike

我编写了一个 Android 应用程序,用于将文本数据发送到 ASP.NET Web 服务器。我正在使用下一个代码通过 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.NET 应用程序中的方法发送的数据 output.writeChars(finalUri) 方法? 此过程应该执行就像下面的描述:

1)我们有 asp.net 表单,它们是之前描述的发送者 android 方法的目标;

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

请帮忙

最佳答案

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
}
});

}
}

关于java - 简单的 android 和 ASP.NET 组合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12673277/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com