Willem Grooters
Willem Grooters

Reputation: 3

HttpSenRequest POST ==> GET?

I have connections to two (unrelated) webservices; both are accessed using POST requests passing a JSON string.

using this logic:

Create a session (InternetOpen)
Connect to server on given port (InternetConnect) (either secured or not)
Create a request on the connection, POST a script (HttpOpenRequest)
In a loop:
 Look for options (InternetQueryOptions) to set flags;
 Set options when instructed
until this os Ok.
Once Ok: in a loop
 Send request (HtpRequest) sending the JSON string.
 Get last error.
 Set security if requested, handle other errors.
until send Ok of some error has occured in processing.
If sending was Ok, get the return data (InternetReadFile)

One site fails in HttpSendRequest, stepping through the code with a sniffer running in parallel, I see:

POST the request, returns status 200

GET (I guess status) returning status 400: with this error tekst.

and it looks as if the data is not accepted by the service.

However, GetLastError returns 0.

The sniffer shows the following output on executing ONLY the HttOpenRequest call: (data obscured, but all valid)

POST HTTP/1.1
Content-Type: application/json
User-Agent: (MyConnector)
Host:(Remote host:port)
Content-Length: 21604
Pragma:no-cache

{ (JSON string) }


HTTP/1.1 301 MOVED PERMANENTLY
Date: Tue, 09 Sep 2014 15:38:31 GMT
Server: Apache/2.2.22 (Ubuntu)
Expires: Tue, 09 Sep 2014 15:38:31 GMT
Cache-Control: no-cache, no-store, must-revalidate, max-age=0
Last-Modified: Tue, 09 Sep 2014 15:38:31 GMT
Location: Vary:
Accept-Encoding
Content-Length: 0
Content-Type: text/html; charset=utf-8

GET HTTP/1.1
User-Agent: MyConnector
Host: :(Remote host:port)
Pragma: no-cache Connection: Keep-Alive



HTTP/1.1 400 BAD REQUEST
Date: Tue, 09 Sep 2014 15:38:31 GMT
Server: Apache/2.2.22 (Ubuntu)
Cache-Control: no-cache, no-store, must-revalidate, max-age=0
Vary: Cookie,Accept-Encoding
Expires: Tue, 09 Sep 2014 15:38:31 GMT
Last-Modified: Tue, 09 Sep 2014 15:38:31 GMT
Content-Length: 34
Connection: close
Content-Type: text/html;charset=utf-8

Only http POST method is accepted.

and GetLastError was not yet called.

Is this 'normal' behaviour, and if so, is there a way to suppress this GET? It may cause the service to abort processing of incoming data.

The weird thing is it has worked; the database of the service contains data that can only be entered using this interface!

As far as it is relevant: The application is developed using Delphi 2007 on a Windows XP professional system, originally tested and working on Windows 8 Professional 64-bit, where it all worked fine. No changes in the code on either sides (Mine hasn't, the other side tells me they didn't change a thing either. The webservice is a Python application).

Upvotes: 0

Views: 111

Answers (1)

Remy Lebeau
Remy Lebeau

Reputation: 597941

According to RFC 2616:

10.3.2 301 Moved Permanently
...
Note: When automatically redirecting a POST request after receiving a 301 status code, some existing HTTP/1.0 user agents will erroneously change it into a GET request.

If that is what WinInet is actually doing, then it is doing the wrong thing. It should not be changing the request type during a 301 redirection. Hard to say for sure without seeing your actual code, not pseudocode.

Upvotes: 0

Related Questions