![]() |
Bash and netcat: Stripping http header
Hi!
I'm getting http-requests with XML-content to a server using netcat as a backend. I want to get the body of the http-request and format it using xmllint. Code:
while true; doThe header is separated from the body with an empty-line which should make it easier for awk. |
What is the output from the script and how does it differ from what you want? Please post in code tags to preserve indentation etc.
|
Hi Catkin!
Let me rephrase I want to transform an http response with header for example: Code:
HTTP/1.1 200 OKCode:
<xml>blablabla</xml> |
Try this one. The code is not yet tested and I'm not yet sure if it will work but you might get the concept.
Code:
#!/bin/bashEdit: New Code: Code:
#!/bin/bash |
Nice konsolebox, but it doesn't work completetly for me.
It read the header ok, but misses the body for some reason, I haven't figured out why yet. This one works for me. It finds the linenumber of the first empty line, which separates the header and body, then I use tail to print the body. Code:
while true; do |
Is that an OK solution for you (in which case, please mark the thread [SOLVED]) or do you want to further refine it?
|
Quote:
Code:
cat data.txt | tr '\n' '#' | sed "s/.*##//" | tr '#' '\n'Code:
<xml>blablabla</xml>Writing your script in Ruby or Python would be better overall, and more flexible. |
Quote:
|
Below is an implementation of wget written in pure bash. The fetch-page function does what you want, skipping over the header and outputting the rest of the page.
Code:
#!/bin/bash |
Quote:
lutusp: Nice! Thanks! You are probably right, Python/Ruby would have been easier. Gnashley: Thanks! |
| All times are GMT -5. The time now is 04:51 AM. |