使用WinHttp发布表单 [英] Posting form using WinHttp
本文介绍了使用WinHttp发布表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在向服务器发布帖子之前,我需要添加任何标题吗?
Do i need to add any headers before making a post to server?
例如,目前我正在尝试发送请求以及帖子数据
For example, Currently I'm trying to send a request along with the post data this way,
LPCWSTR post = L"name=User&subject=Hi&message=Hi";
if (!(WinHttpSendRequest( hRequest,
WINHTTP_NO_ADDITIONAL_HEADERS,
0, (LPVOID)post, wcslen(post),
wcslen(post), 0)))
{
//error
}
?
推荐答案
我想猜猜
- 你需要传递狭窄的字符串不广泛作为post数据。我不知道你是否指定一个内容类型的发布数据,它将指定编码 - 你可能应该,如果它很容易 - 或只是重新编码字符串为UTF-8,或只是组装为一个窄字符串在第一个地方
- 您可能需要在发布数据上显式结束行,即添加
\r\\\
到你的(narrow)字符串 - 我不知道API是否会添加一个,因为我假设你将对二进制数据进行相同的调用。
- you need to pass narrow strings not wide as the post data. I don't know if you're specifying a content type for the posted data which would specify the encoding - you probably should if it's easy to - or just re-encode the string as UTF-8, or just assemble as a narrow string in the first place
- you might need an explicit end-of-line on the post data, i.e. add
\r\n
to your (narrow) string - I don't know if the API's going to add one since I assume you'd make the same call for binary data.
这篇关于使用WinHttp发布表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文