【发布时间】:2020-12-27 20:20:01
【问题描述】:
我正在尝试将我的 PC 名称发送到我的本地服务器并将其保存在一个文件中。
这是我的代码:
#include <stdio.h>
#include <windows.h>
#include <iostream>
#include <fstream>
#include <string>
#include <string.h>
#include <cstring>
#include <Lmcons.h>
#include <unistd.h>
#include <stdlib.h>
#include <WinInet.h>
#include <bits/stdc++.h>
#pragma comment( lib,"Wininet.lib")
using namespace std;
int main() {
TCHAR name [ UNLEN + 1 ];
DWORD size = UNLEN + 1;
static CHAR hdrs[] = "Content-Type: application/x-www-form-urlencoded";
if (GetUserName( (TCHAR*)name, &size ));
static CHAR frmdata[] = "data=", name;
HINTERNET hSession = InternetOpenA("http generic", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
HINTERNET hConnect = InternetConnect(hSession, "127.0.0.1", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 1);
HINTERNET hRequest = HttpOpenRequestA(hConnect, "POST", "/test/index.php", NULL, NULL, NULL, 0, 1);
HttpSendRequestA(hRequest, hdrs, strlen(hdrs), frmdata, strlen(frmdata));
}
我也尝试过使用static CHAR frmdata[] = "data=" + name;,但不起作用。
这是我收到的错误:
错误:'const char [6]' 和 'TCHAR [257] {aka char [257]}' 类型的无效操作数到二进制 'operator+'|
【问题讨论】:
标签: c++ sockets winapi wininet