Hi everyone,
how can I use the function HttpSendRequestW_()
It is referenced on the MSDN of HttpSendRequestA() https://docs.microsoft.com/en-us/window ... ndrequesta
And also on this forum post https://social.msdn.microsoft.com/Forum ... vclanguage
When I try to call it, PB just tells me it's not a function, array etc.
I'm using PureBasic 5.71 LTS (Windows - x64), Windows 10.
Can I use an import command? I'm really not that firm with this kind of thing. One of the reason I love PB is the direct Api-Access.
The problem I'm having is, the same as in the forum post. Because strings are internally stored in unicode, I can't seem to send them with this function. Only the first character gets sent.
I did find the Ascii()-function in the help, so that's what I'm using meanwhile. But I can't be 100% certain that I will never want to send some unicode characters (emojis etc).
Thanks in advance
WinAPI: HttpSendRequestW_() is not a function
Re: WinAPI: HttpSendRequestW_() is not a function
The following example imports HttpSendRequestW() (tested successfully on Windows 10 V1809 x64 with PB 5.71 x86 and x64):
Code: Select all
Import "WinInet.Lib"
HttpSendRequestW(RequestHandle.I, Headers.S, HeadersLength.L, *OptionalData,
OptionalDataLength.L)
EndImport
Debug HttpSendRequestW(0, "", 0, 0, 0)
Re: WinAPI: HttpSendRequestW_() is not a function
Thank you for the code,
but then the issue must lie elsewhere.
The two first lines only send the first character of my payload, while the 3rd works properly.
I'm using infratec's code here, which also handles the opening of the connection and the sending of headers and receiving of answers: viewtopic.php?p=441105#p441105
but then the issue must lie elsewhere.
The two first lines only send the first character of my payload, while the 3rd works properly.
Code: Select all
SendHandle = HttpSendRequest_(*Info\RequestHandle, #Null, 0, @Body$, Len(Body$)) ;only first char is sent
SendHandle = HttpSendRequestW(*Info\RequestHandle, #Null$, 0, @Body$, Len(Body$)) ;only first char is sent
SendHandle = HttpSendRequest_(*Info\RequestHandle, #Null, 0, Ascii(Body$), Len(Body$)) ;full Body$ is sent to server
Re: WinAPI: HttpSendRequestW_() is not a function
The usual encoding to use in HTTP requests is UTF8, which has good support for both ASCII and wide characters. So I would use:Derren wrote:Thank you for the code,
but then the issue must lie elsewhere.
The two first lines only send the first character of my payload, while the 3rd works properly.
I'm using infratec's code here, which also handles the opening of the connection and the sending of headers and receiving of answers: viewtopic.php?p=441105#p441105Code: Select all
SendHandle = HttpSendRequest_(*Info\RequestHandle, #Null, 0, @Body$, Len(Body$)) ;only first char is sent SendHandle = HttpSendRequestW(*Info\RequestHandle, #Null$, 0, @Body$, Len(Body$)) ;only first char is sent SendHandle = HttpSendRequest_(*Info\RequestHandle, #Null, 0, Ascii(Body$), Len(Body$)) ;full Body$ is sent to server
Code: Select all
*d = UTF8(body$)
SendHandle = HttpSendRequest_(*Info\RequestHandle, #Null, 0, *d, MemorySize(*d) ) ;
Re: WinAPI: HttpSendRequestW_() is not a function
Okay, so I tried
But Sharepoint (Microsoft Sharepoint, the REST endpoint I'm trying to trigger) doesn't like it for some reason.
It gives me an error that there are more than one JSON-Root (the body is JSON and the same body works in Ascii (with no Umlauts))
But since I can't see anything wrong with the transmitted data (I tried sending the same request to my own webserver so I can see what is really sent over the wire) and JSON-Lint said it's valid, so I have no idea what Microsoft's Sharepoint is not liking...
Interestingly enough, the response (in German) had an "ü" in it and it was escaped with "\u00fc", so that's what I'm using now and that works.
I'm using
and replace all Umlauts with their \u-escape code.
Thanks for all your input. Really appreciated
Code: Select all
*d = UTF8(body$)
SendHandle = HttpSendRequest_(*Info\RequestHandle, #Null, 0, *d, MemorySize(*d) ) ;
It gives me an error that there are more than one JSON-Root (the body is JSON and the same body works in Ascii (with no Umlauts))
But since I can't see anything wrong with the transmitted data (I tried sending the same request to my own webserver so I can see what is really sent over the wire) and JSON-Lint said it's valid, so I have no idea what Microsoft's Sharepoint is not liking...
Interestingly enough, the response (in German) had an "ü" in it and it was escaped with "\u00fc", so that's what I'm using now and that works.
I'm using
Code: Select all
SendHandle = HttpSendRequest_(*Info\RequestHandle, #Null$, 0, Ascii(Body$), Len(Body$))
Thanks for all your input. Really appreciated
Re: WinAPI: HttpSendRequestW_() is not a function
Don't forget free memory for ASCII and UTF8 functions ...
Code: Select all
;*Body = Ascii(Body$)
*Body = UTF8(Body$)
SendHandle = HttpSendRequest_(*Info\RequestHandle, #Null$, 0, *Body, MemorySize(*Body)
FreeMemory(*Body)
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: WinAPI: HttpSendRequestW_() is not a function
Thanks, I'll add this to the code.
Right now there are only 2 requests and then the program ends, but that's no reason to ommit such important commands.
Right now there are only 2 requests and then the program ends, but that's no reason to ommit such important commands.