相关文章推荐
喝醉的便当  ·  2020-12-31 GIT ...·  1 年前    · 
善良的钥匙扣  ·  GEO Accession viewer·  1 年前    · 
玩篮球的韭菜  ·  七年之痒 ...·  1 年前    · 

WebService ,老技术了。现在也还在用。


我这边的Android终端调试webservice接口,一开始想看日志,用的方法真笨啊。


装了个 WireShark 抓包工具在那看收发的报文,看着真费劲。


又改进,让终端打印出日志来看,使用的是ksoap2框架。


  if(resultSoapObject == null){
                        Log.d(TAG+"请求:",httpTransportSE.requestDump);
                        Log.d(TAG+"应答:",httpTransportSE.responseDump);
                    }


即可。


但是每次调试都要从新编译下载到机器中?效率还是不高。


最后,还是PostMan工具强大好用。


共三步操作,如下:


第一步:POST地址栏里填入WebService地址


第二步:Header里填入两项内容:


SOAPAction: http://NewCap.com/NewCapecWebService/GetCheckNumber

Content-Type: text/xml;charset=utf-8


第三步,填入Body的内容:


示例如下:内容类型选择RAW


<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/">
<v:Header><n0:CredentialSoapHeader xmlns:n0="http://NewCap.com/NewCapecWebService/">
<n0:ID>1</n0:ID><n0:AppTypeID>6</n0:AppTypeID>
<n0:IP>11.11.11.12</n0:IP>
<n0:Timestamp>2019-06-14T08:57:39</n0:Timestamp>
<n0:Random>1</n0:Random>
<n0:Hash>KwEul5zOhWy8lnXdVeDiaw==</n0:Hash>
<n0:Ver>1.0</n0:Ver>
</n0:CredentialSoapHeader>
</v:Header>
<v:Body><GetCheckNumber xmlns="http://NewCap.com/NewCapecWebService/" id="o0" c:root="1">
<cardno i:type="d:string">1454236707</cardno></GetCheckNumber>
</v:Body>
</v:Envelope>


至此,全部结束,直接点击Send按钮提交即可。


截图如下:


image


package com.newcapec.webservice;
import android.annotation.SuppressLint;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.util.Base64;
import android.util.Log;
import com.newcapec.utils.AppConfig;
import com.newcapec.utils.CxfUtils;
import org.apache.http.client.HttpResponseException;
import org.ksoap2.HeaderProperty;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.kxml2.kdom.Element;
import org.kxml2.kdom.Node;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class CommonWebService {
    private static String TAG = "CommonWebService";
    // 含有3个线程的线程池
    private static final ExecutorService executorService = Executors
            .newFixedThreadPool(3);
    // 命名空间
    //private static final String NAMESPACE = AppConfig.xServxiceNameSpace;
    private static final String NAMESPACE = AppConfig.WebServiceNameSpace;
    private static final String TestWebService = "http://xx.168.51.xx:xx/websxcexx/xx.exxx.xxxWeb.asmx";
    static String sIP = "xx.xxxx.xxxxxx.xxxxxxxx";
    static String sID = "1";
    static String sAppTypeID = "x";
    static String sKey = "xxx";
     * @param
     * @param methodName         WebService的调用方法名
     * @param properties         WebService的参数
     * @param webServiceCallBack 回调接口
    public static void callWebService(final String methodName, HashMap<String, Object> properties,
                                      final CommonWebServiceCallRequest webServiceCallBack) {
        // 创建HttpTransportSE对象,传递WebService服务器地址
//        final HttpTransportSE httpTransportSE = new HttpTransportSE(
//                AppConfig.HuaWeiWebService);
        final HttpTransportSE httpTransportSE = new HttpTransportSE(
                TestWebService,10000);
        Element[] header = new Element[1];
        header[0] = new Element().createElement(NAMESPACE,
                "CredentialSoapHeader");
        Element appID = new Element().createElement(NAMESPACE, "ID");
        appID.addChild(Node.TEXT, sID);
        header[0].addChild(Node.ELEMENT, appID);
        Element appTypeID = new Element().createElement(NAMESPACE, "AppTypeID");
        appTypeID.addChild(Node.TEXT, sAppTypeID);
        header[0].addChild(Node.ELEMENT, appTypeID);
        Element iP = new Element().createElement(NAMESPACE, "IP");
        iP.addChild(Node.TEXT, sIP);
        header[0].addChild(Node.ELEMENT, iP);
        SimpleDateFormat sdf = new SimpleDateFormat(
                "yyyy-MM-dd HH:mm:ss", Locale.CHINA);
        SimpleDateFormat sdf1 = new SimpleDateFormat(
                "yyyyMMddHHmmss", Locale.CHINA);
        Date d1 = new Date();
        String dateStr1 = sdf1.format(d1);
        String dateStr0 = sdf.format(d1);
        String[] date1 = dateStr0.split(" ");
        String dateStr = date1[0] + "T" + date1[1];
        Element timestamp = new Element().createElement(NAMESPACE, "Timestamp");
        timestamp.addChild(Node.TEXT, dateStr);
        header[0].addChild(Node.ELEMENT, timestamp);
        Element random = new Element().createElement(NAMESPACE, "Random");
        random.addChild(Node.TEXT, "1");
        header[0].addChild(Node.ELEMENT, random);
        String shash = null;
        byte[] vhash = null;
        try {
            vhash = CxfUtils.computeHash(sID, dateStr1, "1", sKey);
            shash = Base64.encodeToString(vhash, 0, vhash.length, 0);
//          LogUtils.i(TAG, shash);
        } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        Element hash = new Element().createElement(NAMESPACE, "Hash");
        hash.addChild(Node.TEXT, shash);
        header[0].addChild(Node.ELEMENT, hash);
        Element ver = new Element().createElement(NAMESPACE, "Ver");
        ver.addChild(Node.TEXT, "1.0");
        header[0].addChild(Node.ELEMENT, ver);
        // 创建SoapObject对象
        SoapObject soapObject = new SoapObject(NAMESPACE, methodName);
        // SoapObject添加参数
        if (properties != null) {
            for (Iterator<Map.Entry<String, Object>> it = properties.entrySet()
                    .iterator(); it.hasNext(); ) {
                Map.Entry<String, Object> entry = it.next();
                soapObject.addProperty(entry.getKey(), entry.getValue());
        // 实例化SoapSerializationEnvelope,传入WebService的SOAP协议的版本号
        final SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11);
        // 设置是否调用的是.Net开发的WebService
        soapEnvelope.headerOut = header;
        soapEnvelope.bodyOut = soapObject;
        soapEnvelope.implicitTypes = true;// 去除子标签的i:type属性
        soapEnvelope.dotNet = true;// 此处必须为true
        httpTransportSE.debug = true;
        soapEnvelope.setAddAdornments(false);// 去除body标签里的id、root属性
        Log.d("webService:", "url:" + AppConfig.HuaWeiWebService);
        Log.d("webService:", "method:" + methodName);
        // 用于子线程与主线程通信的Handler
        @SuppressLint("HandlerLeak")
        final Handler mHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);
                // 将返回值回调到callBack的参数中
                String retInfo = "";
                if(TextUtils.isEmpty(AppConfig.Cookies)){
                    retInfo = "noCookie";
                webServiceCallBack.callBack((SoapObject) msg.obj,retInfo);
        // 开启线程去访问WebService
        executorService.submit(new Runnable() {
            @Override
            public void run() {
                SoapObject resultSoapObject = null;
                List<HeaderProperty> headerList = new ArrayList<>();
                try {
                    HeaderProperty headerPropertyObj = new HeaderProperty("cookie", AppConfig.Cookies);
                    headerList.add(headerPropertyObj);
                    httpTransportSE.call(NAMESPACE + methodName, soapEnvelope,headerList);
                    if (soapEnvelope.getResponse() != null) {
                        // 获取服务器响应返回的SoapObject
                        resultSoapObject = (SoapObject) soapEnvelope.bodyIn;
                } catch (HttpResponseException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (XmlPullParserException e) {
                    e.printStackTrace();
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    //调试输出错误日志
                    if(resultSoapObject == null){
                        Log.d(TAG+"请求:",httpTransportSE.requestDump);
                        Log.d(TAG+"应答:",httpTransportSE.responseDump);
                    // 将获取的消息利用Handler发送到主线程
                    mHandler.sendMessage(mHandler.obtainMessage(0,
                            resultSoapObject));
     * @author xiaanming
    public interface CommonWebServiceCallRequest {
        public void callBack(SoapObject soapObject,String retinfo);
}


POST /webservice/xxxx.PlatFormWS.asmx HTTP/1.1
User-Agent: ksoap2-android/2.6.0+
SOAPAction: http://xxxcom/xebService/xxxGetCheckNumber
Content-Type: text/xml;charset=utf-8
Connection: close
Accept-Encoding: gzip
Host: 192.168.51.28:8080
Content-Length: 676
<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/"><v:Header><n0:CredentialSoapHeader xmlns:n0="http://xxx.com/xxxxWebService/"><n0:ID>0</n0:ID><n0:AppTypeID>0</n0:AppTypeID><n0:IP>1xxxx.0</n0:IP><n0:Timestamp>20190613182015</n0:Timestamp><n0:Random>1</n0:Random><n0:Hash>oevxmJAN+EvP1Wh0zPDSSg==
</n0:Hash><n0:Ver>1.0</n0:Ver></n0:CredentialSoapHeader></v:Header><v:Body><GetCheckNumber xmlns="http://NewCap.com/NewCapecWebService/"><cardno>1454236707</cardno></GetCheckNumber></v:Body></v:Envelope>
HTTP/1.1 500 Internal Server Error
Server: nginx/1.17.0
Date: Thu, 13 Jun 2019 10:20:08 GMT
Content-Type: text/xml; charset=utf-8
Content-Length: 481
Connection: close
Cache-Control: private
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault><faultcode>soap:Client</faultcode><faultstring>.............................. ---> XML ......(1, 415)............... ---> ............20190613182015.................. AllXsd ......</faultstring><detail /></soap:Fault></soap:Body></soap:Envelope>
                选择合适的方法进行API接口调试
            
随着互联网的快速发展,API(Application Programming Interface)接口在软件开发中扮演着重要的角色。调试API接口是确保系统正常运行的关键步骤之一。本文将介绍如何选择适合的方法进行API接口调试,以确保开发过程的高效进行和应用程序的质量。
Apifox:API 接口自动化测试完全指南
如果要正常访问该接口的数据,需要在 header 中提供 AdminToken: token 头,这是一个常见的需要 JWT 登录认证接口。 很自然的我们想到,如果自动请求登录接口获取 token 值,然后在每次请求前自动带上这个 AdminToken 头不就行了吗,没错就是这样简单,伪代码如下:
用了这个API协作调试工具,忘记了postman
今年三四月份的时候,公司已经上线的项目,发现有部分接口存在重复提交的情况,接口也没做好幂等,导致数据库落下了大量重复数据,于是我就开始优化接口,加了redis分布式锁和一些防重校验,好了,背景介绍完毕。
利用ApiPost接口调试与文档生成工具,提升前、后端工作效率
ApiPost是一个支持团队协作,并可直接生成文档的API调试、管理工具。它支持模拟POST、GET、PUT等常见请求,是后台接口开发者或前端、接口测试人员不可多得的工具 。
vs2017直接联机部署到目标机,右键inf文件,安装。 管理员运行cmd,敲入sc start 驱动名称(实际上对应的是:HKLM/System/CurrentControlSet/Services/<驱动的服务名>) 宿主机windbg在DriverEntry下断, 目标机在cmd再敲入sc stop 驱动名称 目标机在cmd再敲入sc start 驱动名称,宿主机windbg即可断下来。
1、java发HTTP POST请求(内容为xml格式) 2、 android解析XML总结(SAX、Pull、Dom三种方式) 3、Android利用Soap读取WebService并且解析XML的DataSet数据 1、首先不要把这个想的太复杂,它就是使用【soap】协议的请求,数据格式都是【xml】,基础还是http的post请求,但是它的规范显然更多一些,总体逃不过【Request和Response】。
深度学习应用篇-计算机视觉-图像分类[3]:ResNeXt、Res2Net、Swin Transformer、Vision Transformer等模型结构、实现、模型特点详细介绍 10153