Discussion:
How to pass arguments with POST method?
(too old to reply)
Ilho
2009-09-10 22:22:05 UTC
Permalink
Hi,

I am trying to call python script from WinHttp but I have not figured
out how to pass these arguments.

Here is my python script.

def save_data(req, location, data):
f = open(location, 'w')
f.write(data)
f.close()
return apache.OK

I would like to call this script to upload a file to my server but I
could not figured out how to pass location and data information to web
server.
Any help will be appreciated. thank you.
Ilho
2009-09-11 15:43:58 UTC
Permalink
Post by Ilho
Hi,
I am trying to call python script from WinHttp but I have not figured
out how to pass these arguments.
Here is my python script.
    f = open(location, 'w')
    f.write(data)
    f.close()
    return apache.OK
I would like to call this script to upload a file to my server but I
could not figured out how to pass location and data information to web
server.
Any help will be appreciated. thank you.
I felt that my question is too vague so let me clarify little bit
more.
So given the python script on the server, I wrote a client program
that uses WinHttp but I am getting an error when I call
WinHttpSendRequest().

Here is part of my code that calls WinHttpSendRequest().

LPSTR data = "Content-Type: application/x-www-form-urlencoded
\nContent-Length: 29\r\nlocation=abcd.txt&data=\"cool\"\r\n";
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;
}

I am getting 12002 error code right now and if anyone can show me how
I should create data string, I would really appreciate it. Thank you
again.

Loading...