Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

POST via XMLHttpServer fails - maybe wrong Content-Type?

Posted on 2004-11-24
13
Medium Priority
?
350 Views
Last Modified: 2008-01-09
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.
0
Comment
Question by:Andy_Needham
  • 5
  • 4
  • 4
13 Comments
 
LVL 9

Expert Comment

by:jmelika
ID: 12669915
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
 
LVL 1

Author Comment

by:Andy_Needham
ID: 12672724
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
 
LVL 9

Expert Comment

by:jmelika
ID: 12687930
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Expert Comment

by:jmelika
ID: 12687934
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
 
LVL 1

Author Comment

by:Andy_Needham
ID: 12694250
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
 
LVL 9

Accepted Solution

by:
jmelika earned 450 total points
ID: 12698023
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
 
LVL 26

Expert Comment

by:rdcpro
ID: 12712423
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
 
LVL 26

Expert Comment

by:rdcpro
ID: 12712462
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
 
LVL 26

Assisted Solution

by:rdcpro
rdcpro earned 300 total points
ID: 12712516
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
 
LVL 9

Expert Comment

by:jmelika
ID: 12718515
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
 
LVL 26

Expert Comment

by:rdcpro
ID: 12719237
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
 
LVL 1

Author Comment

by:Andy_Needham
ID: 12766477
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
 
LVL 1

Author Comment

by:Andy_Needham
ID: 12885803
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

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
The viewer will learn how to count occurrences of each item in an array.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question