|zyciis| 一个.NET工商银行B2C查询示例 我是用C#的 看不懂他的这是哪个语言 如何译成C#的 谢谢

zyciis164 2008-10-23 02:23:18

#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();
}


谢谢
...全文
272 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
zyciis164 2008-10-23
  • 打赏
  • 举报
回复
好结了 和他们联系一下再说
designonline 2008-10-23
  • 打赏
  • 举报
回复
他是写c的,我建议你跟他们联系,好象他们有其他接口的,我以前跟他们合作过
否则你就用c++转换.net
syc958 2008-10-23
  • 打赏
  • 举报
回复
看到这里:#include "stdafx.h"

#include <windows.h>
#include <wininet.h>
#include <stdio.h>
就应该知道的差不多了吧?
zhengyh5339 2008-10-23
  • 打赏
  • 举报
回复
帮顶
海洋齐齐 2008-10-23
  • 打赏
  • 举报
回复
恩,应该是C或C++
UP
wxg22526451 2008-10-23
  • 打赏
  • 举报
回复
using System;

#include <wininet.h>

private static void Main(int argc, _TCHAR[] argv)
{
if(argc<3)
{
Console.Write("USAGE: {0} [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);

int bRet;
uint 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;
uint length = sizeof(sInfo);
InternetQueryOption(hHttpOpenRequest, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT, (IntPtr)&sInfo, ref length);
Console.Write("The Issuer of the server certificate is:\n{0}\n", sInfo.lpszIssuerInfo);
Console.Write("The Subject of the server certificate is:\n{0}\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");
string pszIssuer = "\0";
string pszSubject = "\0";
int bGotCert = 0;

while(pCertContext = CertEnumCertificatesInStore(hCertStore,pCertContext))
{
Console.Write("The following certificates are available:\n");
CertGetNameString(pCertContext,CERT_NAME_SIMPLE_DISPLAY_TYPE, CERT_NAME_ISSUER_FLAG, null, pszIssuer, 256);
Console.Write("Issuer: {0}\n", pszIssuer);
CertGetNameString(pCertContext,CERT_NAME_SIMPLE_DISPLAY_TYPE,0,null, pszSubject, 256);
Console.Write("Subject: {0}\n", pszSubject);
if ((string.Compare(pszSubject, argv[2]) == 0) && (string.Compare(pszIssuer, sInfo.lpszIssuerInfo) == 0))
{
bGotCert = 1;
Console.Write("\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 != 0)
{
Console.Write("Sending a HTTP request to the web server with the found certificate...\n");
if (InternetSetOption(hHttpOpenRequest, INTERNET_OPTION_CLIENT_CERT_CONTEXT, (IntPtr)pCertContext, sizeof(*pCertContext)))
{
CertDuplicateCertificateContext(pCertContext);
}
}

bRet = HttpSendRequest(hHttpOpenRequest, null, 0, 0, 0);

if (bRet != 0)
{
uint dwCode;
uint dwSize;
dwSize = sizeof(dwCode);
if (!HttpQueryInfo (hHttpOpenRequest, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, ref dwCode, ref dwSize, null))
{
}

if (dwCode == 200)
Console.Write("Request sent to the server successfully.(HTTP Status: {0:D})\n", dwCode);
if (dwCode == 403)
Console.Write("You didn't select a valid certificate. (HTTP Status: {0:D})\n", dwCode);
}
else
{
Console.Write("Untrusted CA.\n");
}

CertFreeCertificateContext(pCertContext);
CertCloseStore(hCertStore,0);

InternetCloseHandle (hInternetSession);
InternetCloseHandle (hInternetConnect);
InternetCloseHandle (hHttpOpenRequest);

Console.Write("Press any key to continue...");
Console.Read();
}

用工具转的。。
下载:C++转换成C#工具(Demo模式的)
gjfizx 2008-10-23
  • 打赏
  • 举报
回复
c++

62,047

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧