POST via XMLHttpServer fails - maybe wrong Content-Type?

I have a VB6 application that uses HTTPs to send files over the internet.  The files contain simple ASCII text - not to any XML or HTML format standard.

Everything normally works well until I POST a file that contains the '&' (ampersand) character; these files get truncated at the receiving end - only the data before the '&' is apparently received.  I am pretty sure that this can be rectified by using a particular 'Content-Type'.  Currently the code does not specify a content-type and I am not sure what the default is.

Any clues gratefully received.
LVL 1
Andy_NeedhamAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jmelikaCommented:
Have you considered doing a replace(content,"&","XX1XX"), or whatever else that would be unique, then at the server you could read it and do another replace(content,"XX1XX","&")?

JM
0
Andy_NeedhamAuthor Commented:
Thanks - but no can do!  The server is not mine - it belongs to a service provider.  At the moment I am replacing '&' with 'and', but there are some circumstances where this is not acceptable.
0
jmelikaCommented:
I see.  Well thats certainly a tricky one.  If your saved file will be displayed as HTML, you might get away with converting your & sign into HEX.  7 in HEX is %26

Good luck!
JM
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

jmelikaCommented:
Sorry.  I meant to say "& in HEX is %26" instead of saying "7 in HEX is %26"  I guess it's time to clean my keyboard :-D

JM
0
Andy_NeedhamAuthor Commented:
Thanks - the trouble is that the file is a fixed format text file that is to be parsed by an automated service;  it doesn't do any interpretting :-(

I still reckon that the answer might lie in the CONTENT-TYPE, but I am not sure where to get a definitive list of the available options and their effect.
0
jmelikaCommented:
Well that's a bummer.

If you only need to know a definitive list of the available CONTENT-TYPE options and their effect, check this MS article out.
http://msdn.microsoft.com/library/default.asp?url=/workshop/networking/moniker/overview/appendix_a.asp

Good luck!
JM
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rdcproCommented:
You need to escape the ampersand into the entity for Ampersand, which is &   The remote server should be able to expand the entity into the character. What you're describing sounds like a parser error.

To verify, try putting a left pointy bracket in the text:  <  

This should break the POST as well.  If so, you need to escape &, < and >.

Regards,
Mike Sharp
0
rdcproCommented:
Oh, to set the content type you use setRequestHeader.

oXMLServerHTTPRequest.setRequestHeader("Content-type", "text/plain")

Or more likely, you want to set it to:

oXMLServerHTTPRequest.setRequestHeader "Content-type", "application/x-www-form-urlencoded"

But then you probably need to URL encode the ampersand, plus any other special character.  

Regards,
Mike Sharp
0
rdcproCommented:
Actually, I suppose it's possible that header case is important, so it should be

oXMLServerHTTPRequest.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"

0
jmelikaCommented:
rdcpro,

I don't believe your suggestion in your first post will make a difference.  He cannot post &amp; since it DOES contain the & sign which we're trying to posting.

I do like your last point about
oXMLServerHTTPRequest.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"

JM
0
rdcproCommented:
But a single ampersand in the body of a POST will still cause the problem unless it is urlencoded...

Whether or not the &amp; works depends on what's parsing the request.  I generally construct XML documents rather than a form body, and post that, because it's easier to validate and read on the remote end.  Obviously here the poster does not have control over the remote server...

In any case, I can repro the issue on one of my local dev machines.  A post containing a form field with an ampersand gets truncated at the ampersand.  Any following fields are undefined.  If I escape the & to %26 (or urlencode the field), no problem -- as long as the content type is set to application/x-www-form-urlencoded.

Regards,
Mike Sharp
0
Andy_NeedhamAuthor Commented:
Thanks for all the input.  I have been conducting some tests with the service provider and I am awaiting results.  It seems that the problem might be with the service provider, in which case I will need advice regarding allocation of points!

Andy
0
Andy_NeedhamAuthor Commented:
The service provider has agree to modify his system, so the problem has disappeared.

Thanks to JM and Mike for your helpful input though!

Andy
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.