#include "stdafx.h"#include <windows.h>
#include <wininet.h>
#include <stdio.h>void main(int argc, _TCHAR *argv[])
{
if(argc<3) {
printf("USAGE: %s [webserver] [username]\n", argv[0]);
return;
} // Open the internet connection
HINTERNET hInternetSession = InternetOpen(
"Wininet Client App", INTERNET_OPEN_TYPE_PRECONFIG,
NULL, NULL, 0) ;
HINTERNET hInternetConnect = InternetConnect(hInternetSession, argv[1],
INTERNET_DEFAULT_HTTPS_PORT, "", "", INTERNET_SERVICE_HTTP, 0, 0);
HINTERNET hHttpOpenRequest = HttpOpenRequest(hInternetConnect, "GET", "",
HTTP_VERSION, "", NULL,
INTERNET_FLAG_SECURE | INTERNET_FLAG_RELOAD | INTERNET_FLAG_KEEP_CONNECTION |
INTERNET_FLAG_IGNORE_CERT_CN_INVALID | INTERNET_FLAG_IGNORE_CERT_DATE_INVALID, 0); BOOL bRet;
DWORD dwLastError = 0; // Send the HTTP request
bRet = HttpSendRequest(hHttpOpenRequest, NULL, 0, 0, 0);
if (!bRet) dwLastError = GetLastError(); // Get the certificate information from the server if available.
INTERNET_CERTIFICATE_INFO sInfo;
DWORD length = sizeof(sInfo);
InternetQueryOption(hHttpOpenRequest, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT,
(LPVOID)&sInfo, &length);
printf("The Issuer of the server certificate is:\n%s\n", sInfo.lpszIssuerInfo );
printf("The Subject of the server certificate is:\n%s\n", sInfo.lpszSubjectInfo ); // Look up the local certicate store to get a certificate that matches the one of the server.
PCCERT_CONTEXT pCertContext = NULL;
HCERTSTORE hCertStore = CertOpenSystemStore(NULL, "MY");
char pszIssuer[256] = "\0";
char pszSubject[256] = "\0";
BOOL bGotCert = FALSE; while(pCertContext = CertEnumCertificatesInStore(hCertStore,pCertContext))
{
printf("The following certificates are available:\n");
CertGetNameString(pCertContext,CERT_NAME_SIMPLE_DISPLAY_TYPE, CERT_NAME_ISSUER_FLAG, NULL,
pszIssuer, 256);
printf("Issuer: %s\n", pszIssuer);
CertGetNameString(pCertContext,CERT_NAME_SIMPLE_DISPLAY_TYPE,0,NULL,
pszSubject, 256);
printf("Subject: %s\n", pszSubject);
if ((strcmp(pszSubject, argv[2]) == 0) && (strcmp(pszIssuer, sInfo.lpszIssuerInfo) == 0)) {
bGotCert = TRUE;
printf("\nFound a certificate that matches the web server certificate.\n");
break;
}
} // If the web server requires a cert and we found a matching one, attach the cert to the request.
if (( dwLastError == ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED ) && bGotCert)
{
printf("Sending a HTTP request to the web server with the found certificate...\n");
if (InternetSetOption(hHttpOpenRequest, INTERNET_OPTION_CLIENT_CERT_CONTEXT,
(void*)pCertContext, sizeof(*pCertContext)) )
{
CertDuplicateCertificateContext(pCertContext);
}
} bRet = HttpSendRequest(hHttpOpenRequest, NULL, 0, 0, 0); if (bRet) {
DWORD dwCode, dwSize;
dwSize = sizeof(dwCode);
if ( !HttpQueryInfo (hHttpOpenRequest, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &dwCode, &dwSize, NULL))
{
}
if (dwCode == 200)
printf("Request sent to the server successfully.(HTTP Status: %d)\n", dwCode);
if (dwCode == 403)
printf("You didn't select a valid certificate. (HTTP Status: %d)\n", dwCode);
} else {
printf("Untrusted CA.\n");
} CertFreeCertificateContext(pCertContext);
CertCloseStore(hCertStore,0); InternetCloseHandle (hInternetSession);
InternetCloseHandle (hInternetConnect);
InternetCloseHandle (hHttpOpenRequest);
printf("Press any key to continue...");
getchar();
}能不能帮说明一下上面的代码呢
我都看不到他请求的地址是什么
然后我要怎么个请求法
以前做快钱 ebuy的时候都是用WebService的
但这个工行的说明文档就是看不懂 谢谢
解决方案 »
- ASP.NET 与 SYBASE的问题 解决别赠分!
- webpart小问题
- SiteMapPath控件位置问题
- 一个很郁闷的错误。请高手解决。只有一部分人浏览的时候会出现这种错误。
- 如果在winform程序中释放引用的ActiveX
- 討論:將URL作为参数的值传递后取值的问题
- <%#做了一个基类page页面.想在这个页面中动态引入样式表文件.请在线的高手帮帮忙,在线等.
- 怎样获取文件名称?
- Vista 下运行程序时,报告错误!
- 谁能告诉我哪里有比较好的用c#写的aspx.net的论坛,最好有完整的源码
- 一个网络公司的门户网站开场页用flash合适吗
- 求自定义用户表信息表其权限表、角色表的程序例子?
argv[1]就是url
如果你不急,等下午有空帮你写个。
INTERNET_DEFAULT_HTTPS_PORT, "", "", INTERNET_SERVICE_HTTP, 0, 0);
这行代码应该是,
argv[1]应该是请求的的地址
printf("USAGE: %s [webserver] [username]\n", argv[0]);
return;
}
C#使用http可以参考:
HTTP协议编程 C#
http://info.52z.com/html/23853.html