gpt4 book ai didi

c++ - 错误 C2664 : 'HttpOpenRequestW' : cannot convert parameter 6 from 'LPTSTR [2]' to 'LPCWSTR

转载 作者:行者123 更新时间:2023-11-30 02:46:42 29 4
gpt4 key购买 nike

您好,我的 json 数据发布请求代码出现以下错误

错误 1 ​​error C2664: 'HttpOpenRequestW' : 无法将参数 6 从 'LPTSTR [2]' 转换为 'LPCWSTR *' c:\users\gbsindia1\documents\visual studio 2010\projects\program\program\program1.cpp

#include "stdafx.h"
#include <windows.h>
#include <Wininet.h>
#include <stdio.h>
#include <tchar.h>


int main(int argc, char* argv[])




{
HINTERNET hInternet = InternetOpen(_T("MyApp"), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);

HINTERNET hConnect = InternetConnect(hInternet, _T("192.168.1.7"),
INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);

LPTSTR rgpszAcceptTypes[] = {_T("application/json"), NULL};
HINTERNET hRequest = HttpOpenRequest(hConnect, _T("POST"),
_T(":8080/hellowword.jsp"), NULL, NULL, rgpszAcceptTypes, 0, 0); // here the error occure

HttpAddRequestHeaders(hRequest, _T("Content-Type: application/json\r\n"), -1,
HTTP_ADDREQ_FLAG_ADD);

char *JsonData = "...";
HttpSendRequest(hRequest, NULL, 0, JsonData, strlen(JsonData));

DWORD StatusCode = 0;
DWORD StatusCodeLen = sizeof(StatusCode);
HttpQueryInfo(hRequest, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &StatusCode,
&StatusCodeLen, NULL);

if (StatusCode == 200)
{
// use InternetQueryDataAvailable() and InternetReadFile()
// to read any response data as needed...
}

InternetCloseHandle(hRequest);
InternetCloseHandle(hConnect);
InternetCloseHandle(hInternet);
}

最佳答案

尝试使用:

LPCWSTR rgpszAcceptTypes[] = {L"application/json", NULL};

代替:

LPTSTR rgpszAcceptTypes[] = {_T("application/json"), NULL};

关于c++ - 错误 C2664 : 'HttpOpenRequestW' : cannot convert parameter 6 from 'LPTSTR [2]' to 'LPCWSTR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23359957/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com