2 haiquanking HaiQuanKing 于 2016.02.26 13:48 提问

安卓端调用WebService传参,服务端接收不了数据

代码如下:
public class MainActivity extends Activity {
private static final String NAMESPACE="http://service.ams.com/";
private static final String URL="http://220.231.228.87:8080/InstallWebService/intallService";
private static final String METHOD_NAME="installDevice";
private SoapObject detail;
private TextView message;
private Handler handler;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    message=(TextView) findViewById(R.id.message);
    this.findViewById(R.id.button).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            new Thread(){
                public void run() {
                    installtion();
                };
            }.start();


        }
    });
    handler=new Handler(){
        public void handleMessage(Message msg) {
            message.setText("从webService获取的数据:"+(String)msg.obj);
        };
    };

}




protected void installtion() {
    SoapObject rpc = new SoapObject(NAMESPACE,METHOD_NAME); 
    String json="{"+"";
    json+="\"userId\""+":"+"\""+207+"\""+",";
    json+="\"loginId\""+":"+"\""+"AHAHAHAHAA"+"\""+",";
    json+="\"deviceId\""+":"+47397+",";
    json+="\"groupId\""+":"+559+",";
    json+="\"Time\""+":"+"\""+new SimpleDateFormat().format(new Date())+"\""+",";
    json+="\"brand\""+":"+"\"宝马\""+",";
    json+="\"model\""+":"+"\"R1\""+",";
    json+="\"color\""+":"+"\"黑\""+",";
    json+="\"carNum\""+":"+"\"粤B88888\""+",";
    json+="\"carName\""+":"+"\"宝马\""+",";
    json+="\"connectionType\""+":"+"1"+",";
    json+="\"oilPump\""+":"+"1"+",";
    json+="\"VDD\""+":"+"\"黑色\""+",";
    json+="\"GND\""+":"+"\"黑色\""+",";
    json+="\"deviceImgUrl\""+":"+"\"\""+",";
    json+="\"connectionIntallImgUrl\""+":"+"\"\""+",";
    json+="\"obligateUrl\""+":"+"\"\""+",";
    json+="\"InstallPosition\""+":"+"\"车头\""+",";
    json+="\"DBServer\""+":"+1+"}";
    JSONObject myjson = null;
    try {
        myjson=new JSONObject(json);
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }


    rpc.addProperty("arg0",myjson.toString()); 
     SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
     envelope.bodyOut = rpc;  
        // 设置是否调用的是dotNet开发的WebService  
        envelope.dotNet = true;  
        // 等价于envelope.bodyOut = rpc;  
        envelope.setOutputSoapObject(rpc);  

        HttpTransportSE transport = new HttpTransportSE(URL);  
        try {  
            // 调用WebService  
            transport.call(NAMESPACE+METHOD_NAME, envelope);  
        } catch (Exception e) {  
            e.printStackTrace();  
        }  

        // 获取返回的数据  
        SoapObject object = (SoapObject) envelope.bodyIn;  
        // 获取返回的结果  
        String result = object.getProperty(0).toString();
        Message msg=new Message();
        msg.obj=result;
        handler.sendMessage(msg);
}




@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

}
调用成功了,不过传参传不了,哪位大神帮忙看下,谢谢了

1个回答

oyljerry
oyljerry   Ds   Rxr 2016.02.26 22:19

先抓包分析看看数据包是在什么地方丢弃了。

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!