web services -如何在c++中通过wininternet库连接到webservice
web services - How can I connect to a webservice through winIntet library in c++?
我创建了一个webService:
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService
{
public WebService()
{
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
}
服务引用为http://localhost:4653/WebService.asmx。
现在,我需要通过一个cpp项目访问这个web服务。为此,我使用winInet库:
HINTERNET handle = InternetOpen("Upload", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
if (handle)
{
HINTERNET handleConnect = InternetConnect(handle, "localhost:4653", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, NULL, NULL);
if (handleConnect)
{
if (HINTERNET handleOpenReq = HttpOpenRequest(handleConnect, TEXT("POST"), TEXT("/WebService.asmx/HelloWorld"), NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0))
{
if (HttpSendRequest(handleOpenReq, NULL, 0, NULL, 0))
cout << "succeed" << endl;
else
{
DWORD p = GetLastError();
}
}
然而httpendrequest没有成功,GetLastError返回12029,即试图连接服务器失败。我如何解决这个问题,使它能很好地连接到webService?是不是我发错了什么参数?谢谢你,
不要使用InternetConnect,尝试使用InternetOpenUrl()
相关文章:
- 当套接字连接断开时检测C/C++Unix
- 无法在windows上使用mingw将sqlite3与c连接
- 到连接组件算法的问题(递归)
- QTcpSocket在不阻塞GUI的情况下重新连接到服务器
- 无法在C++中建立与MySQL数据库的连接
- PC中的程序和PHONE中的本机描述应用程序之间的数据连接
- 在Qt Creator中,如何在连接到正在运行的进程后查看控制台输出
- 连接 dockerized 模型和 dockerized 数据库时出现"无法 SQLConnect"错误
- 使用 bfs 解决连接组件问题时得到错误的答案
- 在C++的两个字符串中连接以逗号分隔的唯一值
- 如何修复valgrind启动时的致命错误(与libc6-dbg和libc6-dbg:i386连接)
- C++应用程序 MySQL odbc 数据库连接错误:在引发"otl_tmpl_exception<>"实例后终止调用
- OSX蓝牙打开RFCOMMChannelAsync声称已连接,但未建立连接,并且从未调用过委托
- 在 libcurl 连接池中预创建连接
- 套接字连接"Operation not permitted"错误,甚至使用升压/平发器根.cpp
- libcurl 和 DNS ttl 中的内部连接管理
- 如何应用 libcurl 的持久连接选项
- 提升 ASIO - io_service 不要等待连接到线程
- WinSock2:connect() 提供"连接被拒绝"
- 升压信号2将插槽传递到成员功能以断开连接