How to construct WinHttpSendRequest for POST?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<span class="fixed_width" style="font-family:Courier,Monospaced Hi,
 
<span class="fixed_width" style="font-family:Courier,Monospaced I am trying to POST data on the webserver and I have a python script that will take name and data to create a file.
<span class="fixed_width" style="font-family:Courier,Monospaced I have found a few examples of GET method but I could not quite find any complete example for POST method and I am getting an error when I call WinHttpSendRequest().
<span class="fixed_width" style="font-family:Courier,Monospaced <br/>
<span class="fixed_width" style="font-family:Courier,Monospaced Here is part of my code that calls WinHttpSendRequest(). <br/>
<span class="fixed_width" style="font-family:Courier,Monospaced
<pre>LPSTR data = "Content-Type: application/x-www-form-urlencoded
nContent-Length: 29rnlocation=abcd.txt&data="cool"rn";
DWORD data_len = strlen(data);

hRequest = WinHttpOpenRequest(hConnect, L"POST", L"/sd.py/save_data",
NULL, WINHTTP_NO_REFERER,
WINHTTP_DEFAULT_ACCEPT_TYPES, 0);

if (!hRequest) {
wprintf(L"WinHttpOpenRequest failed (%d)n", GetLastError());
goto out;
}

if (WinHttpSendRequest(hRequest, WINHTTP_NO_ADDITIONAL_HEADERS, 0,
(LPVOID)data, data_len, data_len, 0) != TRUE) {
wprintf(L"WinHttpSendRequest failed (%d)n", GetLastError());
goto out;
}
[/code]
<br/>
<div class=qt style=" <span class="fixed_width" style="font-family:Courier,Monospaced <br/>
<span class="fixed_width" style="font-family:Courier,Monospaced I am getting 12002 error code right now and if anyone can show me how <br/> I should create data string, I would really appreciate it. Thank you <br/> in advance.<br/>

View the full article
 
Back
Top