- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个小程序可以将文件上传到服务器。出于测试目的,我使用了我自己的由 WebAmp 软件创建的本地服务器。我的程序将使用 PHP 脚本上传文件,该脚本将从程序中接受文件并将它们存储到指定位置的服务器上。现在我对此感到困惑,我必须将这个 PHP 文件放在我的系统中,这样我的程序才能与这个脚本交互并成功发送文件。这是我的代码
int main()
{
static TCHAR frmdata[] = "-----------------------------7d82751e2bc0858\r\nContent-Disposition: form-data; name=\"uploadedfile\"; filename=\"D:\\er.txt\"\r\nContent-Type: text/plain\r\n\r\nfile contents here\r\n-----------------------------7d82751e2bc0858--\r\n";
static TCHAR hdrs[] = "Content-Type: multipart/form-data; boundary=---------------------------7d82751e2bc0858";
HINTERNET hSession = InternetOpen("MyBrowser",INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
if(!hSession)
{
cout<<"Error: InternetOpen";
}
HINTERNET hConnect = InternetConnect(hSession, _T("http://localhost"),INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 1);
if(!hConnect)
{
cout<<"Error: InternetConnect";
}
//HINTERNET hRequest = HttpOpenRequest(hConnect, (const char*)"POST",_T("upload.php"), NULL, NULL, (const char**)"*/*\0", 0, 1);
LPCTSTR rgpszAcceptTypes[] = {_T("*/*"), NULL};
HINTERNET hRequest = HttpOpenRequest(hConnect, (const char*)"POST",
_T("upload.php"), NULL, NULL,
rgpszAcceptTypes, 0, 1);
if(hRequest==NULL)
{
cout<<"Error: HttpOpenRequest";
}
BOOL sent= HttpSendRequest(hRequest, hdrs, strlen(hdrs), frmdata, strlen(frmdata));
if(!sent)
{
cout<<"Error: HttpSendRequest "<<GetLastError();
}
//close any valid internet-handles
InternetCloseHandle(hSession);
InternetCloseHandle(hConnect);
InternetCloseHandle(hRequest);
getchar();
return 0;
}
PHP脚本
<?php
$uploaddir = './'; // Relative Upload Location of data file
if (is_uploaded_file($_FILES['uploadedfile']['tmp_name'])) {
$uploadfile = $uploaddir . basename($_FILES['uploadedfile']['name']);
echo "File ". $_FILES['uploadedfile']['name'] ." uploaded successfully. ";
if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $uploadfile)) {
echo "File is valid, and was successfully moved. ";
}
else
print_r($_FILES);
}
else {
echo "Upload Failed!!!";
print_r($_FILES);
}
?>
最佳答案
lpszServerName 参数应该是主机名,而不是 URL。
将 http://localhost
更改为 localhost
。
将此代码放在 HTTPSendRequest
下方以打印响应 header 和内容
//Print the first 2k of the response headers and content
char buffer[2048] = {};
DWORD bufferSize = sizeof(buffer);
BOOL success = HttpQueryInfo(hRequest, HTTP_QUERY_RAW_HEADERS_CRLF, buffer, &bufferSize, NULL);
if(!success)
{
std::cout<<"Error: HttpQueryInfo "<< GetLastError();
return 0;
}
std::cout << buffer << std::endl;
ZeroMemory(buffer, sizeof(buffer));
success = InternetReadFile(hRequest, buffer, sizeof(buffer), &bufferSize);
if(!success)
{
std::cout << "Error: InternetReadFile " << GetLastError();
return 0;
}
std::cout << buffer << std::endl;
关于php - HttpSendRequest 12005 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18373115/
我正在使用 WinInet 向 apache 网络服务器发出一个简单的 POST 请求。我使用 base 64 对数据进行编码。问题是,每个 + 字符都被空格字符替换。 为什么会这样,我怎样才能发出正
在这段代码中,我从网站获取一个字符串并将其显示在标签上。在标签上显示字符串真的很慢!大约 10 秒。但是在控制台 println (date) 上打印字符串时是立即的。我该如何解决这个问题?
我的应用程序中的 HTTP 请求出现问题,如果远程文件与本地文件大小相同(即使其修改时间不同,因为其内容已更改),尝试下载它很快返回并且没有下载较新的文件。 简而言之,我遵循的过程是:使用 INTER
我必须使用 delphi 将文件发送到 php 脚本。我最终选择使用 Wininet 函数,因为我必须通过 NTLM 身份验证代理。 当我发送文件时,我的内容请求的每个字符之间有空字符(00): PO
我有一个小程序可以将文件上传到服务器。出于测试目的,我使用了我自己的由 WebAmp 软件创建的本地服务器。我的程序将使用 PHP 脚本上传文件,该脚本将从程序中接受文件并将它们存储到指定位置的服务器
我创建了一个 Win32 服务,它使用 WinInet 向远程主机发送 HTTP 请求。在我的计算机 (WinXP SP2) 上,在我们的 QoS 团队 (Win2003 Server) 的测试工作站
在连接到 REST 服务时,使用 InternetSetOption 设置用户名 和密码。我注意到当我调用 HttpSentRequest 时 WinInet 不发送 Authorization he
在我们的程序中,每次需要进行 HTTP 请求时都会创建一个新线程,并且可以同时运行多个线程。我遇到的问题是,如果我已经有两个线程在运行,它们在调用 HttpSendRequest() 之后循环读取 I
我在使用 Delphi XE2 应用程序时遇到问题。有时,WinInet 对 ASMX 服务的调用会阻塞并且永远不会返回 - 用户必须从任务管理器终止进程才能关闭应用程序。要连接到 ASMX 服务应用
我正在从我的 C++ 应用向服务器上的 PHP 脚本发送一个 HTTP POST 请求。使用 HttpOpenRequest/HttpSendRequest/etc。目前,它会等待 PHP 脚本在 H
我正在创建一个可以从 Internet 下载文件的程序。在下载文件之前,我想获取文件大小,我已经尝试过 InternetQueryDataAvailable,但它给出的值为 0。 然后我尝试了 hHt
我正在制作一个 C++ 代理,它将使用 HttpSendRequest() 将信息(例如系统主机名)发布回中央服务器。我希望它回发的信息之一是操作系统。我创建了以下函数来获取系统主机名。 wstrin
我正在使用 wininet 连接到需要客户端证书的 URL。为了测试我的“自动纠错”,我在没有客户端证书的情况下进行此连接,行为是调用我的 SelectCertificate 函数。 我故意不将所有参
我是一名优秀的程序员,十分优秀!