
dreamscd
Members-
Posts
5 -
Joined
-
Last visited
Everything posted by dreamscd
-
I'm glad you can reply to my poor English. OK, I'll get to know it another way.
-
Thanks for your reply, but I have used both ways to test. You said about the WinHTTP Session Overview section called "Posting Data to the Server", I read it in detail, and also read the relevant content of the WinHttpSendRequest function. but I have tested the post request sent in these two ways, and the "EntityChunkCount" flag is always 0, I don't know if you noticed There is a comment after "_WinHttpSendRequest" in my test script. When I tested, I used two methods to send the request, and the results were the same. Let's talk about my test process: Method 1: send immediately _WinHttpSendRequest($hRequest, "Content-Type: application/x-www-form-urlencoded", $sAdditionalData) Use wireshark to capture packets and see that the post data is in the request headers, only one packet is sent Method 2: WinHttpWriteData _WinHttpSendRequest($hRequest, "Content-Type: application/x-www-form-urlencoded", Default, StringLen($sAdditionalData)) ;$sAdditionalData) _WinHttpWriteData($hRequest, $sAdditionalData) Also use wireshark to capture packets and see that the post data is not in the request headers, but in the latter packet, two packets are sent. The same is that no matter which method is used to send the post request, the "EntityChunkCount" flag is always 0 The following is the test script and result of method 1 ; =============testgetPost.au3 #include "WinHttp.au3" $sUserName = "SomeUserName" $sEmail = "some.email@something.com" $sDomain = "http://127.0.0.1:9000" $sPage = "/a3server/posttest" $sAdditionalData = "name=" & $sUserName & "&email=" & $sEmail $hOpen = _WinHttpOpen() If @error Then MsgBox(0, "open", "open error") $hConnect = _WinHttpConnect($hOpen, $sDomain) If @error Then MsgBox(0, "Connect", "Connect error") $hRequest = _WinHttpOpenRequest($hConnect, "POST", $sPage, Default, "http://192.168.1.196:9000/a3server/posttest", "*/*") If @error Then MsgBox(0, "OpenRequest", "OpenRequest error") _WinHttpSendRequest($hRequest, "Content-Type: application/x-www-form-urlencoded", $sAdditionalData) If @error Then MsgBox(0, "SendRequest", "SendRequest error:" & @error) ;_WinHttpWriteData($hRequest, $sAdditionalData) _WinHttpReceiveResponse($hRequest) If @error Then MsgBox(0, "ReceiveResponse", "ReceiveResponse error") If _WinHttpQueryDataAvailable($hRequest) Then Global $sHeader = _WinHttpQueryHeaders($hRequest) MsgBox(0, "header", $sHeader & @CRLF) EndIf Dim $sReturned If _WinHttpQueryDataAvailable($hRequest) Then Do $sReturned &= _WinHttpReadData($hRequest) Until @error EndIf _WinHttpCloseHandle($hRequest) _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) MsgBox(4096, "return", $sReturned) ClipPut($sReturned) ConsoleWrite($sReturned & @CRLF) I added a "msgbox" before "_WinHttpSendRequest" of WinHttp UDF to view the call parameters of dllcall, and the result is as follows ;========WinHttp.au3 Func _WinHttpSendRequest($hRequest, $sHeaders = Default, $vOptional = Default, $iTotalLength = Default, $iContext = Default) __WinHttpDefault($sHeaders, $WINHTTP_NO_ADDITIONAL_HEADERS) __WinHttpDefault($vOptional, $WINHTTP_NO_REQUEST_DATA) __WinHttpDefault($iTotalLength, 0) __WinHttpDefault($iContext, 0) Local $pOptional = 0, $iOptionalLength = 0 If @NumParams > 2 Then Local $tOptional $iOptionalLength = BinaryLen($vOptional) $tOptional = DllStructCreate("byte[" & $iOptionalLength & "]") If $iOptionalLength Then $pOptional = DllStructGetPtr($tOptional) DllStructSetData($tOptional, 1, $vOptional) EndIf If Not $iTotalLength Or $iTotalLength < $iOptionalLength Then $iTotalLength += $iOptionalLength MsgBox(0,"DllCall","WinHttpSendRequest:"&@crlf& _ "hRequest:"&@TAB&@TAB& $hRequest&@crlf& _ "lpszHeaders:"&@TAB& $sHeaders&@crlf& _ "dwHeadersLength:"&@TAB& 0&@crlf& _ "lpOptional:"&@TAB& $pOptional&@crlf& _ "dwOptionalLength:"&@TAB& $iOptionalLength&@crlf& _ "dwTotalLength:"&@TAB& $iTotalLength&@crlf& _ "dwContext:"&@TAB& $iContext) Local $aCall = DllCall($hWINHTTPDLL__WINHTTP, "bool", "WinHttpSendRequest", _ "handle", $hRequest, _ "wstr", $sHeaders, _ "dword", 0, _ "ptr", $pOptional, _ "dword", $iOptionalLength, _ "dword", $iTotalLength, _ "dword_ptr", $iContext) If @error Or Not $aCall[0] Then Return SetError(1, 0, 0) Return 1 EndFunc ;==>_WinHttpSendRequest Hello from the AutoIt HTTP Server. POST request received!<br><br><pre>POST Request Info: Request struct size = 4960 Bytes received = 302 Full URL = http://127.0.0.1:9000/a3server/posttest Host = 127.0.0.1:9000 AbsPath = /a3server/posttest QueryString = Verb = 6 EntityChunkCount = 0 Request Headers: Accept: */* Connection: Keep-Alive Content-Length: 48 Content-Type: application/x-www-form-urlencoded Host: 127.0.0.1:9000 Referer: http://192.168.1.196:9000/a3server/posttest User-Agent: Mozilla/5.0 (Windows NT 10.0) WinHttp/1.6.4.2 (WinHTTP/5.1) like Gecko </pre> Why is the value of EntityChunkCount not set, this is bothering me😵
-
Thanks for such a quick reply👏 I don't know if you have figured out why the request sent by WinHTTP (DLL or COM) does not have the EntityCount flag, I have always wondered why it is, please let me know if you know, thank you! Looking forward to your new version!!!
-
Download httpapi_ v1.1.5. Zip. Use "example_httpapi_web_server.au3" to start the HTTP service. When I use "testgetpost.au3" to send a post request, the server returns Entitychunkcount is always 0 and no body is returned ; ===========testgetpost.au3 #include "WinHttp.au3" $sUserName = "SomeUserName" $sEmail = "some.email@something.com" $sDomain = "http://127.0.0.1:9000" $sPage = "/a3server/posttest" $sAdditionalData = "name=" & $sUserName & "&email=" & $sEmail $hOpen = _WinHttpOpen() If @error Then MsgBox(0, "open", "open error") $hConnect = _WinHttpConnect($hOpen, $sDomain) If @error Then MsgBox(0, "Connect", "Connect error") $hRequest = _WinHttpOpenRequest($hConnect, "POST", $sPage, Default, "http://192.168.1.196:9000/a3server/posttest", "*/*") If @error Then MsgBox(0, "OpenRequest", "OpenRequest error") _WinHttpSendRequest($hRequest, "Content-Type: application/x-www-form-urlencoded", Default, StringLen($sAdditionalData)) ;$sAdditionalData) If @error Then MsgBox(0, "SendRequest", "SendRequest error:" & @error) _WinHttpWriteData($hRequest, $sAdditionalData) _WinHttpReceiveResponse($hRequest) If @error Then MsgBox(0, "ReceiveResponse", "ReceiveResponse error") If _WinHttpQueryDataAvailable($hRequest) Then Global $sHeader = _WinHttpQueryHeaders($hRequest) MsgBox(0, "header", $sHeader & @CRLF) EndIf Dim $sReturned If _WinHttpQueryDataAvailable($hRequest) Then Do $sReturned &= _WinHttpReadData($hRequest) Until @error EndIf _WinHttpCloseHandle($hRequest) _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) MsgBox(4096, "return", $sReturned) ClipPut($sReturned) ConsoleWrite($sReturned & @CRLF) ; =============The following returned data Hello from the AutoIt HTTP Server. POST request received!<br><br><pre>POST Request Info: Request struct size = 4960 Bytes received = 302 Full URL = http://127.0.0.1:9000/a3server/posttest Host = 127.0.0.1:9000 AbsPath = /a3server/posttest QueryString = Verb = 6 EntityChunkCount = 0 Request Headers: Accept: */* Connection: Keep-Alive Content-Length: 48 Content-Type: application/x-www-form-urlencoded Host: 127.0.0.1:9000 Referer: http://192.168.1.196:9000/a3server/posttest User-Agent: Mozilla/5.0 (Windows NT 10.0) WinHttp/1.6.4.2 (WinHTTP/5.1) like Gecko </pre> I don't know if I haven't done anything well. I use the post request sent by "winhttp.au3",“Entitychunkcount” is always 0,I don't know why😵
-
My English is not good. about POST, use "WinHttp.au3" to send a post Request, the "example_httpapi_web_server" don't got the post body, maybe can do this by “HttpReceiveRequestEntityBody”. ; example_httpapi_web_server.au3 ;Func process_post_request($pRequest) If $tRequest.pEntityChunks > 0 Then $sResponse &= @CRLF & "Request EntityChunks Body:" & @CRLF $sResponse &= _HTTPAPI_GetRequestBody($tRequest) & @CRLF & @CRLF EndIf If BitAND( $tRequest.Flags , $__HTTPAPI_HTTP_REQUEST_FLAG_MORE_ENTITY_BODY_EXISTS ) Then $sResponse &= @CRLF & "Request Body:" & @CRLF $sResponse &= _HTTPAPI_HttpReceiveRequestEntityBody($ghRequestQueue, $tRequest.RequestId) & @CRLF & @CRLF EndIf ; HttpApi.au3 ;====================== ;HTTP REQUEST FLAG ;====================== Global $__HTTPAPI_HTTP_REQUEST_FLAG_MORE_ENTITY_BODY_EXISTS = 1 Global $__HTTPAPI_HTTP_REQUEST_FLAG_IP_ROUTED = 2 ; #FUNCTION# ==================================================================================================================== ; Name ..........: _HTTPAPI_HttpReceiveRequestEntityBody ; Description ...: Returns the request body. ; Syntax ........: _HTTPAPI_HttpReceiveRequestEntityBody($hRequestQueue,$RequestId) ; Parameters ....: $hRequestQueue A handle to the request queue to receive the request from. ; : $RequestId This value is returned in the RequestId member of the HTTP_REQUEST structure by a call to the HttpReceiveHttpRequest function. ; Return values .: Success: A string containing the request body. ; Author ........: Dreamscd ; Related .......: ; Remarks .......: ; =============================================================================================================================== Func _HTTPAPI_HttpReceiveRequestEntityBody($hRequestQueue,$RequestId) _DebugOut(@CRLF & "Function: HttpReceiveRequestEntityBody") Local $aResult = "", $sRequestBody = "" Local $EntityBufferLength = 2048 Local $EntityBuffer = DllStructCreate( StringFormat("byte EntityBuffer[%i];", $EntityBufferLength) ) Local $pEntityBuffer = DllStructGetPtr($EntityBuffer) While 1 ;Call API function $aResult = DllCall($__HTTPAPI_ghHttpApiDll, "int", "HttpReceiveRequestEntityBody", _ "handle", $hRequestQueue, _ "uint64", $RequestId, _ "ulong", 0, _ "struct*", $pEntityBuffer, _ "ulong", DllStructGetSize($EntityBuffer), _ "ulong*", 0, _ "ptr", Null) If @error Then $__HTTPAPI_gsLastErrorMessage = "DllCall function failed." Return SetError(1, @error, "") EndIf ;Set last error message Switch $aResult[0] Case $__HTTPAPI_ERROR_NO_ERROR If $aResult[6] <> 0 Then ;BytesRead $sRequestBody &= _WinAPI_GetString($pEntityBuffer,False) EndIf Case $__HTTPAPI_ERROR_HANDLE_EOF If $aResult[6] <> 0 Then $sRequestBody &= _WinAPI_GetString($pEntityBuffer,False) ExitLoop Else ExitLoop EndIf Case $__HTTPAPI_ERROR_INVALID_PARAMETER $__HTTPAPI_gsLastErrorMessage = "An invalid parameter was passed To the function." Return SetError(2, $aResult[0], "") Case $__HTTPAPI_ERROR_DLL_INIT_FAILED $__HTTPAPI_gsLastErrorMessage = "The calling application did not call HttpInitialize before calling this function." Return SetError(2, $aResult[0], "") Case Else $__HTTPAPI_gsLastErrorMessage = "Unrecognized error - check winerror.h for more information." Return SetError(2, $aResult[0], "") EndSwitch WEnd Return $sRequestBody EndFunc