Modify HTTP Header

Jonas

Member
Licensed User
Longtime User
I am programming an app that is going to function as a existing PC program. It connects to a machine's SOAP web service to get data.

I got it running and communicating with the machine but when I try my program on a slightly newer machine with updated software I only receive "400 Bad Request". I tried the PC program and it can communicate without problem.
I'm using WireShark to monitor the communication and I can verify the XML SOAP request is identical between my program and the PC software.

The differences is in the header.

Due to the sensitive nature of my project I have altered some names.


My app sending:
POST / HTTP/1.1
Content-Type: text/xml;charset=ISO-8859-1
SOAPAction: http://www.death.star/laser/command#ReadRequest
Content-Length: 469
Host: 10.10.10.2:500
Connection: Keep-Alive

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><AP-MSG:ReadRequest xmlns:AP-MSG="http://www.death.star/laser/command" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"><RequestBase ClientRequestHandle="1" ReturnItemTime="true" ReturnItemName="true"/><ItemRequestSpec MaxAge="PT0.1S"/><ItemList><Item ItemName="Death.Star.Laser.UnitID"/></ItemList></AP-MSG:ReadRequest></SOAP-ENV:Body></SOAP-ENV:Envelope>


From machine:
HTTP/1.1 400 Bad Request
Content-Type: text/xml; charset=ISO-8859-1
Content-Length: 0

PC Program sending:
POST * HTTP/1.1
Content-Type:text/xml;charset=ISO-8859-1
Connection:Keep-Alive
SOAPAction:http://www.death.star/laser/command#ReadRequest
Content-Length:469

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><AP-MSG:ReadRequest xmlns:AP-MSG="http://www.death.star/laser/command" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"><RequestBase ClientRequestHandle="1" ReturnItemTime="true" ReturnItemName="true"/><ItemRequestSpec MaxAge="PT0.1S"/><ItemList><Item ItemName="Death.Star.Laser.UnitID"/></ItemList></AP-MSG:ReadRequest></SOAP-ENV:Body></SOAP-ENV:Envelope>



From Machine:
HTTP/1.1 200 OK
Content-Type: text/xml; charset=ISO-8859-1
Content-Length: 583
Data comes here.....

The differences in the header are:
APP:pOST / HTTP/1.1
PCP:pOST * HTTP/1.1
DIF: "/" instead of "*"

APP add a space after the ":"

APP add "HOST:"

Is there anyway that I can exactly control how the Header looks like?

/J
 
Last edited:

Jonas

Member
Licensed User
Longtime User
Yes I am using .SetHeader to add the SOAPAction and Content-Type but I want to remove the HOST string. I tried RemoveHeader("HOST") but it didnt remove it.

Is there anyway to see the full header list before executing the POST?
 
Upvote 0

Jonas

Member
Licensed User
Longtime User
Ok so I created a socket connection to the server and sent the Header and Soap msg as the PC program did and I get a positive response. But when I add the "Host :10.10.10.2:500" into the header I recieve a "Bad Request"

So my question remains, is it possible to remove "Host:" from the Header when using HTTPClient?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The HOST header is required according to the specifications:
A client MUST include a Host header field in all HTTP/1.1 request messages . If the requested URI does not include an Internet host name for the service being requested, then the Host header field MUST be given with an empty value. An HTTP/1.1 proxy MUST ensure that any request message it forwards does contain an appropriate Host header field that identifies the service being requested by the proxy. All Internet-based HTTP/1.1 servers MUST respond with a 400 (Bad Request) status code to any HTTP/1.1 request message which lacks a Host header field.
 
Upvote 0

Jonas

Member
Licensed User
Longtime User
Funny that the machines web server responds the opposite. Well I guess I am stuck using Sockets. Hopefully it wont be much of a problem when using it with AsyncStreams.
Guess I cant get everything served on a silver plate, ha ha.

Thanks for your help!
 
Upvote 0
Top