QT 和webservice的demo,查询手机号码归属地信息
C++访问WebService (需要密码验证)
文章链接:https://blog.csdn.net/z_y__l/article/details/105811563.
查询手机号码归属地信息的qt demo
在这个链接中有很多好玩的webservice的接口 http://www.webxml.com.cn/zh_cn/web_services.aspx
找到查询手机号码归属地信息的地址:http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl
通过gsoap生产C++文件
创建QT DEMO
以下为具体的代码和Pro文件
提示gSoap的“error LNK2001: 无法解析的外部符号 _namespaces”解决方法 是添加预定义 WITH_NONAMESPACES
//CPP 文件
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "gsoap28/soapMobileCodeWSSoapProxy.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
setWindowTitle("查询手机号码归属地webservice demo");
connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(slotSearch()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::slotSearch()
{
MobileCodeWSSoapProxy mcsp;
_ns1__getMobileCodeInfo para;
_ns1__getMobileCodeInfoResponse resp;
auto archiveWString = ui->lineEdit->text().toStdWString();
auto mobileCode = const_cast<wchar_t *>(archiveWString.c_str());//wstring 转为 wchar_t *
para.mobileCode = mobileCode;
if(mcsp.getMobileCodeInfo(¶,resp) != SOAP_OK)
{
ui->textEdit->append(QString("search %1 is failed").arg(ui->lineEdit->text()));
return;
}
QString recv;
recv = QString::fromStdWString(resp.getMobileCodeInfoResult);
ui->textEdit->append(recv);
}
pro文件
#-------------------------------------------------
#
# Project created by QtCreator 2020-05-27T22:25:55
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = soapphone
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
#提示gSoap的“error LNK2001: 无法解析的外部符号 _namespaces”解决方法 是添加预定义 WITH_NONAMESPACES
DEFINES += QT_DEPRECATED_WARNINGS WITH_NONAMESPACES
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
CONFIG += c++11
SOURCES += \
main.cpp \
mainwindow.cpp \
gsoap28/soapC.cpp \
gsoap28/soapMobileCodeWSSoapProxy.cpp \
gsoap28/stdsoap2.cpp
HEADERS += \
mainwindow.h \
gsoap28/MobileCodeWSSoap.nsmap \
gsoap28/soapH.h \
gsoap28/soapMobileCodeWSSoapProxy.h \
gsoap28/soapStub.h \
gsoap28/WebService.h \
gsoap28/stdsoap2.h
FORMS += \
mainwindow.ui
LIBS += -lWs2_32
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target